Skip to main content
Home Forums Silverlight Programming Programming with .NET - General Consuming a WCF-Service hosted in a Console-Application from Silverlight.
12 replies. Latest Post by Yi-Lun Luo - MSFT on September 10, 2008.
(0)
My.self
Member
4 points
10 Posts
09-09-2008 9:36 AM |
Hi,
im trying since three days to consume a WCF-Service which is hosted in a console application in a Silberlight2 Beta2 application but is still not succeeded…
My Service app.config looks like:
<?xml version="1.0" encoding="utf-8" ?><configuration> <system.serviceModel> <behaviors> <serviceBehaviors> <behavior name="HelloServiceBehavior"> <serviceMetadata /> </behavior> </serviceBehaviors> </behaviors> <services> <service behaviorConfiguration="HelloServiceBehavior" name="MilkHost.Service1"> <endpoint address="http://localhost:8080/HelloService/" binding="basicHttpBinding" bindingConfiguration="" contract="MilkHost.IService1" />
<endpoint address="http://localhost:8080/HelloService/MEX/" binding="mexHttpBinding" bindingConfiguration="" contract="IMetadataExchange" /> </service> </services> </system.serviceModel></configuration>
I start the service in the Main function of my console application in the following manner:
using (ServiceHost serviceHost = new ServiceHost(typeof(Service1))) { // Open the ServiceHostBase to create listeners and start listening for messages. serviceHost.Open();
// The service can now be accessed. Console.WriteLine("The service is ready."); Console.WriteLine("The service is running in the following account: {0}", WindowsIdentity.GetCurrent().Name); Console.WriteLine("Press <ENTER> to terminate service."); Console.WriteLine(); Console.ReadLine();
// Close the ServiceHostBase to shutdown the service. serviceHost.Close();
}
Then I started the console application and clicked “Add service Reference” in my Silverlight project…
The wizard created the following configuration file:
<configuration> <system.serviceModel> <bindings> <basicHttpBinding> <binding name="BasicHttpBinding_IService1" maxBufferSize="65536" maxReceivedMessageSize="65536"> <security mode="None" /> </binding> </basicHttpBinding> </bindings> <client> <endpoint address="http://localhost:8080/HelloService/" binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IService1" contract="MilkClient.ServiceReference1.IService1" name="BasicHttpBinding_IService1" /> </client> </system.serviceModel></configuration>
In my Silverlight page I have written the following code:
public Page() { InitializeComponent();
ServiceReference1.Service1Client client = new MilkClient.ServiceReference1.Service1Client(); client.GetDataCompleted += new EventHandler<MilkClient.ServiceReference1.GetDataCompletedEventArgs>(client_GetDataCompleted); client.GetDataAsync(123); }
void client_GetDataCompleted(object sender, MilkClient.ServiceReference1.GetDataCompletedEventArgs e) { string str = e.Result; }
But when I call the “client.GetDataAsync(123)” function I get the exteption:
{System.ServiceModel.ProtocolException: The remote server returned an unexpected response: (404) Not Found. at System.ServiceModel.AsyncResult.End[TAsyncResult](IAsyncResult result) at System.ServiceModel.Channels.ServiceChannel.SendAsyncResult.End(SendAsyncResult result) at System.ServiceModel.Channels.ServiceChannel.EndCall(String action, Object[] outs, IAsyncResult result) at System.ServiceModel.ClientBase`1.ChannelBase`1.EndInvoke(String methodName, Object[] args, IAsyncResult result) at MilkClient.ServiceReference1.Service1Client.Service1ClientChannel.EndGetData(IAsyncResult result) at MilkClient.ServiceReference1.Service1Client.MilkClient.ServiceReference1.IService1.EndGetData(IAsyncResult result) at MilkClient.ServiceReference1.Service1Client.OnEndGetData(IAsyncResult result) at System.ServiceModel.ClientBase`1.OnAsyncCallCompleted(IAsyncResult result)}
Sergey.L...
Contributor
7202 points
1,342 Posts
09-09-2008 9:41 AM |
Did you add the clientaccesspolicy.xml file to your WCF service?
09-09-2008 9:54 AM |
Where should i add this file?
I know that i have to copy this file to the root folder of my application on the IIS...
But when i copy it to the execution folder of my console application nothing happens...
HarshBar...
Star
9908 points
1,719 Posts
09-09-2008 10:08 AM |
Dont Paste this in Your Console application Folder.
Instead of that Put this file to Your Service Project's folder where service is there.
You Can Create your Service in the Same Aspx Project also which is Hosting your Silverlight Project.
Then Policy file is not Required...
09-09-2008 10:09 AM |
You should place file at root of IIS.
For more details look here.
09-09-2008 10:13 AM |
But i dont want to host my service on IIS!
I want to run it in a console application!!
09-09-2008 10:14 AM |
Paste That File in Console Application's Root.....
09-09-2008 10:24 AM |
I have already tryed!
My clientaccesspolicy.xml file looks like:
<?xml version="1.0" encoding="utf-8" ?><access-policy> <cross-domain-access> <policy> <allow-from http-request-headers="*"> <domain uri="*"/> </allow-from> <grant-to> <resource path="/" include-subpaths="true"/> </grant-to> </policy> </cross-domain-access></access-policy>
09-09-2008 10:40 AM |
Did you look this post?
09-09-2008 10:41 AM |
Can You Specify What Error are you Getting..
09-09-2008 10:55 AM |
InnerException=null
09-10-2008 3:39 AM |
hi,
1)Is Your Console Application and Your silverlight Project is in Same Solution???
2)when you are running Your Silverlight Project your Console Application is Running??
3)You are able to Browse to Url which you are reffering like: http://localhost:8080/HelloService/ when your Silverlight application is Running...
I think there might Be Problem due to that...
Yi-Lun L...
All-Star
25052 points
2,747 Posts
09-10-2008 11:51 PM |
Hello, since you're hosting the WCF service in a console application, you don't have a web server, and thus does not have the concept of "root folder of the web server". You have to find a way to manually serve the cross domain policy file. A common solution is to create a REST service with UriTemplate = "clientaccesspolicy.xml" that returns the content of the policy file. Please refer to this thread.