Skip to main content

MSDN

Answered Question Using an own WCFService with silverlight2b2RSS Feed

(0)

suntsu
suntsu

Member

Member

29 points

24 Posts

Using an own WCFService with silverlight2b2

Hi
I'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?

cheers
manuel

WiproSachin
WiproSa...

Member

Member

323 points

87 Posts

Re: Using an own WCFService with silverlight2b2

 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 


 

Please Mark as Answer if your problem is solve with above solution

Regards

Sachin
Consultant

suntsu
suntsu

Member

Member

29 points

24 Posts

Re: Using an own WCFService with silverlight2b2

Hi

 As i wrote, it's a standalone WCF Service. There is no Web.config at all.

And the App.config looks like this:

<?xml version="1.0" encoding="utf-8" ?>

<configuration>

<system.serviceModel>

<behaviors>

<serviceBehaviors>

<behavior name="WCF.Service1Behavior">

<serviceMetadata httpGetEnabled="true" />

<serviceDebug includeExceptionDetailInFaults="false" />

</behavior>

</serviceBehaviors>

</behaviors>

<services>

<service behaviorConfiguration="WCF.Service1Behavior" name="WCF.Service1">

<endpoint address="" binding="basicHttpBinding" contract="WCF.IService1">

<identity>

<dns value="localhost" />

</identity>

</endpoint>

<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />

<host>

<baseAddresses>

<add baseAddress="http://localhost:8731/Design_Time_Addresses/WCF/Service1/" />

</baseAddresses>

</host>

</service>

</services>

</system.serviceModel>

</configuration>

doolittle
doolittle

Member

Member

74 points

26 Posts

Re: Using an own WCFService with silverlight2b2

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...

suntsu
suntsu

Member

Member

29 points

24 Posts

Re: Re: Using an own WCFService with silverlight2b2

Hi

 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 Luo - MSFT
Yi-Lun ...

All-Star

All-Star

25090 points

2,750 Posts

Answered Question

Re: Using an own WCFService with silverlight2b2

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>

shanaolanxing - I'll transfer to the Windows Azure team, and will have limited time to participate in the Silverlight forum. Apologize if I don't answer your questions in time.

Xblovecls1
Xblovecls1

Member

Member

20 points

40 Posts

Re: Using an own WCFService with silverlight2b2

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

<configuration>

<system.serviceModel>

<bindings>

<basicHttpBinding>

<binding name="SearchGameSoap" maxBufferSize="65536" maxReceivedMessageSize="65536">

<security mode="None" />

</binding>

</basicHttpBinding>

</bindings>

<client>

<endpoint address="http://webapp1.durationinc.com/public/microsoft/wsSearchGame/SearchGame.asmx"

binding="basicHttpBinding" bindingConfiguration="SearchGameSoap"

contract="SearchGameService.SearchGameSoap" name="SearchGameSoap" />

</client>

</system.serviceModel>

</configuration>

and error happened in my reference.vb file and underline sentence cause the problem.

Public Function EndinsSearch(ByVal result As System.IAsyncResult) As SearchGameService.Response Implements SearchGameService.SearchGameSoap.EndinsSearch

Dim _args((0) - 1) As Object

Dim _result As SearchGameService.Response = CType(MyBase.EndInvoke("insSearch", _args, result),SearchGameService.Response)

Return _result

End Function

 

 

suntsu
suntsu

Member

Member

29 points

24 Posts

Re: Re: Using an own WCFService with silverlight2b2

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?


cheers

Yi-Lun Luo - MSFT
Yi-Lun ...

All-Star

All-Star

25090 points

2,750 Posts

Answered Question

Re: Re: Re: Using an own WCFService with silverlight2b2

You need to create another WCF service, since the address, binding, and contract are all different.

shanaolanxing - I'll transfer to the Windows Azure team, and will have limited time to participate in the Silverlight forum. Apologize if I don't answer your questions in time.

suntsu
suntsu

Member

Member

29 points

24 Posts

Re: Re: Re: Re: Using an own WCFService with silverlight2b2

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

cheers

rajesh shirpuram
rajesh ...

Contributor

Contributor

2315 points

507 Posts

Re: Re: Re: Re: Re: Using an own WCFService with silverlight2b2

thanks suntsu for sharing the code.

Thanks
Rajesh Shirpuram

(If this has answered your question, please click on "mark as answer" on this post. Thank you!)

juanjo.arana
juanjo....

Member

Member

2 points

1 Posts

Re: Using an own WCFService with silverlight2b2

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

  • Unanswered Question
  • Answered Question
  • Announcement