Skip to main content
Microsoft Silverlight
Home Forums General Silverlight Programming Programming with .NET - General Using an own WCFService with silverlight2b2
11 replies. Latest Post by juanjo.arana on June 25, 2010.
(0)
suntsu
Member
29 points
24 Posts
07-30-2008 2:52 AM |
HiI've create a WCF Service.There are two project for this. First the WCF Service which contains ServiceContract/OperationContract and a console start application for this service which has only the following code: static void Main(string[] args) { Type serviceType = typeof(WCF.PersonService); using (ServiceHost host = new ServiceHost(serviceType)) { host.Open(); Console.WriteLine("The Service is available"); Console.ReadLine(); host.Close(); } } The binding for this WCF Service is set to basicHTTP.How can i use this service in silverlight?If i try to use the proxy class created by the svcutil.exe, it got an error with System.Runtime.Serialization.ExtensionDataObject. If i start the WCF Service, it runs on http://localhost:8080/MyWCFService. But im not able to add this as a Service Reference to my silverlight project. It throws the following error://The message with Action '' cannot be processed at the receiver, due to a ContractFilter mismatch at the EndpointDispatcher. //This may be because of either a contract mismatch (mismatched Actions between sender and receiver) //or a binding/security mismatch between the sender and the receiver. //Check that sender and receiver have the same contract and the same binding (including security requirements, e.g. Message, Transport, None).
Any hints how to use a wcf service which isn't hosted in a webserver.And there is btw the question about the clientaccesspolicy.xml. Do i need to provide it if my wcf is not hosted in a webserver?
cheersmanuel
WiproSa...
323 points
87 Posts
07-30-2008 5:26 AM |
Hi ,
At present Silverlight only support BasicHttpBinding and but WCF default binding is (WsHttpBinding)
go to Web.config of WCF serivces
under services element
<endpoint address="" binding="basicHttpBinding" contract="CustomerService.IService1">
Please Answer if your problem is solve with above solution
07-30-2008 5:38 AM |
Hi
As i wrote, it's a standalone WCF Service. There is no Web.config at all.
And the App.config looks like this:
<
</
doolittle
74 points
26 Posts
07-30-2008 8:33 AM |
It's strange that your baseAddress is different from the one you mentioned in your first post.Or do you change that in code?
Maybe try it in a WPF-application (add service reference).If that fails aswell there must be something wrong in your service...
07-30-2008 9:02 AM |
Yes, i changed the URI, so this is not the problem.
And since it is a WCF service which i start myself via a console application, i don't know how to get this service reference.
I've also created an WPF application which uses the proxy class generated by SvcUtil.exe, and with this, i can access this WCF service without problems.
The question is how to get either the service reference from such a service or how to use the proxy class generated by the SvcUtil.exe in a silverlight application
cheers
Yi-Lun ...
All-Star
25090 points
2,750 Posts
08-01-2008 4:09 AM |
Hello, if you type "http://localhost:8731/Design_Time_Addresses/WCF/Service1/?wsdl" in the browser's address bar, do you see the WSDL file? If you can, try to add a service reference in your Silverlight application. In the Address TextBox, type the above address. Then click the Go Button. The proxy class should be generated. If you can't see the WSDL file in browser, chances are that your service configuration is incorrect. In that case, can you share a sample project?
For cross domain issues, you need to create a REST service to return the cross domain policy file.
First create a new WCF service like this. Note the UriTemplate is clientaccesspolicy.xml. Together with BaseAddress, you'll be able to access the service with URI such as http://localhost:8731/clientaccesspolicy.xml. Also note you must return a Message.
[ServiceContract]public interface ICrossDomainService{[OperationContract][WebGet(UriTemplate = "clientaccesspolicy.xml")]Message ReturnPolicyFile();}
To implement the service, you read the cross domain policy file and construct a Message:
public Message ReturnPolicyFile(){FileStream fs = File.Open("clientaccesspolicy.xml", FileMode.Open);XmlReader reader = XmlReader.Create(fs);Message result = Message.CreateMessage(MessageVersion.None, "", reader);return result;}
Now create a new ServiceHost:
ServiceHost host2 = new ServiceHost(typeof(CrossDomainService));host2.Open();
Finally, configure the service:
<endpointBehaviors><behavior name="webBehavior"><webHttp/></behavior></endpointBehaviors>
<service behaviorConfiguration="TheService.CrossDomainServiceBehavior"name="TheService.CrossDomainService"><endpoint address="" binding="webHttpBinding" behaviorConfiguration="webBehavior" contract="TheService.ICrossDomainService"><identity><dns value="localhost" /></identity></endpoint><endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" /><host><baseAddresses><add baseAddress="http://localhost:8731/" /></baseAddresses></host></service>
Xblovecls1
20 points
40 Posts
08-01-2008 4:18 AM |
When i try to insert data in my data by using webservcie, i get this error "The remote server returned an unexpected response: (404) Not Found.",what seems to be the problem.
My codes is below for ServiceReferences.ClientConfig
and error happened in my reference.vb file and underline sentence cause the problem.
08-05-2008 2:44 AM |
Hi. Thanks for your answer. Now i'm able to get the wsdl, and i can ad it as service reference to my silverlight project.
Now i've a question about the ClientAccessPolicy:Do i have to create a second WCF Service for hosting this policy file, or can i add it to my WCF server with which i provide my data?
08-05-2008 3:43 AM |
You need to create another WCF service, since the address, binding, and contract are all different.
08-05-2008 8:13 AM |
Hi.
Thanks a lot, now it works.
If you like to get the source of my demo application, i've put it onto: http://www.suntsu.ch/serendipity/index.php?/archives/158-Use-WCF-service-from-a-Silverlight-application.html
rajesh ...
Contributor
2315 points
507 Posts
08-05-2008 9:22 AM |
thanks suntsu for sharing the code.
juanjo....
2 points
1 Posts
06-25-2010 6:44 AM |
1st: THANK YOU
2nd: The code in ReturnPolicyFile() blocks the xml file.
I've modifed the code as follows and the file is not blocked:
public Message ReturnPolicyFile()
{
var reader = XmlReader.Create(@"clientaccesspolicy.xml");
var policyMssg = Message.CreateMessage(MessageVersion.None, "", reader);
return policyMssg;
}
Thanks again!
juanjo.arana