Silverlight WCF service - wcf

Initially created a WCF service with one method and everything works fine. I tried to add a new method to the service and for some reason when I try to update the service it does not find this new method. Any advice?

Is the service in the same solution as the Silverlight app? That seems to help when updating the service. Also, are you sure your service is compiling and starting correctly? If there is a problem, VS can't read the WSDL and nothing gets updated.
Other than that, sometimes VS just doesn't refresh it right for me and it's faster just to re-create it.

I had to add
[OperationContract]
Above each new function in the IService1.cs file. So now the IService1.cs file looks like this:
[ServiceContract]
public interface IService1
{
[OperationContract]
List func1();
[OperationContract]
double func2();
}

Related

WCF RIA services and WSDL generation

Need help on an issue I am having. I inherited this WCF RIA project and am trying to understand a couple of things.
When I publish the project, how does the WSDL get generated and put on the URL that I published to?
And I want to incorporate FaultException handling so as to transmit the exceptions to the client side. I read some stuff regarding the FaultException on the web and was able to get a small sample working with the regular WCF service.
I thought it would be similar within my actual project. But unfortunately I am running into some issues(probably due to my lack of WCF + RIA services knowledge).
So in my actual project my Context class derives off of LinqToEntitiesDomainService.
I created a new ContextFaultException class which had some methods to capture some custom error messaging.
Then I applied the [FaultContract(typeof(ContextFaultException))] to some of the methods in my Context class. Everything compiles and all is fine. But when I published to a website and then when I added this service reference to the client, I don't see my new ContextFaultException in the Reference.cs file that's generated.
I thought may be moving it within the Context class will solve the issue. So I made my ContextFaultException class as an inner class of this Context class but I am running into some other issues. Before I try to figure out these issues, I just want to know if this the right approach?
Any suggestions/pointers??
TIA
The URL must be formatted to get to the namespace wdsl
for example:
namespace My.Namespace.Services
{
[EnableClientAccess()]
public partial class MyClassName : LinqToEntitiesDomainService<XXX>
{
....
}
}
Then use the following pattern for the url
http://YOURHOST/APP/Services/My-Namespace-Services-MyClassName.svc?wsdl
Use "-" for the "."

Can I expose two methods in my Server with NServiceBus?

I was looking an answer for this but I couln't find it. As you know, the NServiceBus library came with a sample that's call WCF Integration. It has an interface that the Server exposes as a WCF service, right? This interface has only one method inside. My idea is to have more than one method inside that interface, is this possible?
I have my own project, in which I have my interface with more than one method and my idea is that this WCF Service to have a method similar to "Process" from the sample, that publish messages.
Code:
[ServiceContract]
public interface ICancelOrderService
{
[OperationContract(Action = "http://tempuri.org/IWcfServiceOf_CancelOrder_ErrorCodes/Process", ReplyAction = "http://tempuri.org/IWcfServiceOf_CancelOrder_ErrorCodes/ProcessResponse")]
ErrorCodes Process(CancelOrder request);
[OperationContract]
ErrorCodes HelloWorld(CancelOrder request);
}
public class CancelOrderService : WcfService<CancelOrder, ErrorCodes>{}
I trie to inherit from ICancelOrderService, but didn't work.
So, any suggestions? Thanks people...
Regards, Matias.
thanks for your soon response. Maybe my explanation wasn't clear enough. I have my Server that inherits from WcfService, but my idea is to have more than one OperationContract, one similar to Process, and the others ones commons Wcf OperationContract, that they won't interact with NSB.
[ServiceContract]
public interface ICancelOrderService
{
[OperationContract(Action = "http://tempuri.org/IWcfServiceOf_CancelOrder_ErrorCodes/Process", ReplyAction = "http://tempuri.org/IWcfServiceOf_CancelOrder_ErrorCodes/ProcessResponse")]
ErrorCodes Process(CancelOrder request);
[OperationContract]
void HelloWorld(int var);
}
My code will be something like that. With your response I realize that the code of the first post was wrong.
So, is this possible, or I have to look other way to implement this?
Thanks, Matias
The WCF service that is exposed is only to get messages onto the bus. Once the messages is on the bus it will be dispatched to the appropriate message handler. You can then Publish from your handler. NSB will expose methods for each message handler that inherits the WcfService<T,K> class. Just keep using that class to expose more methods.

Using WCF and NetNamedPipeBinding for IPC

I'm trying to learn WCF to use it as an IPC mechanism for a host/plugin system. The host needs to be able to call the plugin to Start/Stop it, and the plugin needs to call the server back to perform logging.
I made a simple test case where the host creates an endpoint on net.pipe://localhost/SampleServer with the following ServiceContract:
[ServiceContract]
public interface IWcfServer
{
[OperationContract]
void Log(string message);
}
And the plugin creates an endpoint on net.pipe://localhost/SampleClient with the following ServiceContract:
[ServiceContract]
public interface IWcfClient
{
[OperationContract]
string Init();
}
Here's a sample of how I'm setting up each endpoint:
this.server = new ServiceHost(this);
this.server.AddServiceEndpoint(typeof(IWcfServer),
new NetNamedPipeBinding(),
"net.pipe://localhost/SampleServer");
this.server.Open();
And here's a sample of how I'm making the calls:
ChannelFactory<IWcfClient> factory = new ChannelFactory<IWcfClient>(
new NetNamedPipeBinding(),
new EndpointAddress("net.pipe://localhost/SampleClient"));
IWcfClient client = factory.CreateChannel();
using ((IClientChannel)client)
{
client.Init());
}
I already confirmed that the host can call plugin.Init(), and the plugin can call host.Log(message) without issues. However, if this following scenario happens:
Host calls plugin.Init()
During the execution of plugin.Init(), the plugin attempts to call host.Log(message)
The applications freezes, and I get a TimeoutException after 1min. Anyone has any ideas on what I'm doing wrong?
what is the InstanceContextMode of the service host ? If it is a singleton, it will block until Init() returns - resulting in a circular dependency.
1 min is the standard wcf timeout.
Do you have a circular reference?
Also, why do you have 2 contracts, when you make a call to client.init who is listening?
Turn on E2E tracing for WCF to check what exactly is timing out. - http://msdn.microsoft.com/en-us/library/ms733025.aspx. Besides your methods might be causing a deadlock since init might require log and log might require init to happen first or something like that.
"net.pipe://localhost/SampleServer"
"net.pipe://localhost/SampleClient"
You have two different URL for the Server and for the Client. It is a problem!

WCF service contract not working with Microsoft Chart control as param

I have the following service contract:
using System.Windows.Forms.DataVisualization.Charting;
...
[ServiceContract]
public interface IMyService
{
[OperationContract]
bool Print(Chart chart);
}
When I run attempt to host the service (in Visual Studio under the WCFTestClient) I get the following exception:
Failed to add a service. Service metadata may not be accessible. Make sure your service is running and exposing metadata.
It seems to be an issue with the Chart type itself as changing this to something else works fine.
Any ideas?
Most likely this is due to the Chart type not being serializable.
Try sending over an object containing the chart data instead.
You can also check out the Chart Serializer
http://msdn.microsoft.com/en-us/library/system.windows.forms.datavisualization.charting.chartserializer(VS.100).aspx
It helps handle the serialization for you, which I suspect is probably the reason why you may be getting the message posted.

ServiceKnownTypeAttribute doesn't pop up in WSDL

I have an service Interface:
[ServiceContract]
[ServiceKnownType(typeof(Models.ArticleImage))]
public interface IPhotoManagementService
{
[OperationContract]
bool Login(string username, string password);
[OperationContract]
bool IsLoggedIn();
[OperationContract]
void UpdateImage(string articleID, string selectedImage);
}
As you can see I specify a typeof(Models.ArticleImage) on my ServiceContract.
So building the WSDL of this service should cause ArticleImage to pop up in the WSDL. Unfortunarly this doesn't happen at all. Why is that?
ArticleImage has DataContract on it. And when I return an ArticleImage in my interface, then the WSDL does pick up ArticleImage.
Edit: it doesn't even pop up in the service reference in the consuming project!
This is the result of a lot of testing:
The model I'm trying to add is a LINQ to SQL model.
When I add a normal model with ServiceKnownType it works.
When I use my LINQ to SQL entities in my Interface it works.
When I add my LINQ to SQL entity through ServiceKnownType it doesn't pop up.
Only types used as input/output parameters of service contract operations are published in the WSDL.
Why would it need to? Where does your service expose something that could possibly be an ArticleImage?
Re your comment; when using [ServiceKnownType], the extra trype is still exposed in the "mex" (consumed via "svcutil") - but not by the WSDL. Are you using a WCF client? It should appear (I've just checked... it did). In general, though, returning vague data from a web-service isn't a great idea... sub-types, sure! Dictionary<string,ArticleImage> or even Dictionary<string,SomeBaseType> (with [KnownType] etc), fine! But object, HashTable, etc - aren't a good idea (IMO).
You might also just return a list of your type (List<ArticleImage>) which will work in all scenarios (and be easy for WSDL etc); and let the client make the dictionary at their end.
With regards to LINQ-to-SQL; objects for "mex" need to be decorated with [DataContract] / [DataMember]. You can do this in the designed by toggling the "serialization" property for the dbml. With this set (Serialization Mode = Unidirectional), it should work. To be honest, though, I think you be better-off just adding a dummy method that makes the type explicit on the API.