Testing a WCF Service - wcf

I have a few questions about setting up and running a WCF service after done coding it.
I've created my service. I'm able to right-click it in VS and choose to run it in the browser and it comes up.
Now I want to test tie service by creating a new C# project and adding a service reference to my service (.svc).
When I try to add the service reference it can't find it (e.g. http://localhost:55129/Cars.svc).
So do I need to have my service project running in order to add it?
And would I need to set it up in IIS? Or are people mainly running it from within VS, running the WCF project itself?
Here is the error I get when trying to add that service endpoint:
There was an error downloading http://localhost:55129/Cars.svc/_vti_bin/ListData.svc/$metadata.
The request failed with HTTP status 400: Bad Request.
Metadata contains a reference that cannot be resolved: http://localhost:55129/Cars.svc.
Content Type application/soap+xml; charset=utf-8 was not supported by service http://localhost:55129/Events.svc. The client and service bindings may be mismatched.
The remote server returned an error: (415) Cannot process the message because the content type 'application/soap+xml; charset=utf-8' was not the expected type 'text/xml; charset=utf-8'..
If the service is defined in the current solution, try building the solution and adding the service reference again.

If you're using the development web service, it has to be running for you to generate client proxies.
Hosting in IIS is more convenient in this respect as it is always running even if you don't have your solution open.

Related

Receiving default website when invoking web service

I have created a web service and can invoke the methods using the WCF Test Client when the service is running on my local server (ASP.NET Development Server).
However, when I publish the web service to QA server and invoke one of the methods, again with the Test Client, I get the following error message:
The content type text/html; charset=UTF-8 of the response message does not match the content type of the binding (text/xml; charset=utf-8).
Upon inspection of the request using Fiddler I see that what I am getting back is the default page as if I had visited the mywebservice.svc:
You have created a service.
To test this service, you will need to create a client and use it to call the service. You can do this using the svcutil.exe tool from the command line with the following syntax:
I do not understand why the default page would be returned instead of invoking the method. Do I need to do anything on the server to allow the method to be invoked? Do I need to set up any MIME types?

How do I access a workflow service in silverlight?

I have one worflow service named GetDataWorkflowService.xamlx that I want to use in Silverlight.
When I add a service reference to my application, it gives a message 'This Operation is not supported for the relative URI.' It still adds the reference, however.
When I use the referece:
Servicelient proxy=new ServiceClient();
proxy.GetDataCompleted += (o, a) => Debug.WriteLine("Result is " + a.Result);
proxy.GetDataAsync(123);
I get the following error:
An error occurred while trying to make a request to URI 'http://localhost:1234/GetDataWorkflowService.xamlx'. This could be due to attempting to access a service in a cross-domain way without a proper cross-domain policy in place, or a policy that is unsuitable for SOAP services. You may need to contact the owner of the service to publish a cross-domain policy file and to ensure it allows SOAP-related HTTP headers to be sent. This error may also be caused by using internal types in the web service proxy without using the InternalsVisibleToAttribute attribute. Please see the inner exception for more details.
I don't understand what's happening.
A few things:
What happens if you use the WCF Test Client to call GetData()? Do you get an error or does that work just fine. If you get an error here concentrate on the server parts.
What happens if you set a service reference from a console application and call your workflow service. Same error or does that work?
Is the workflow service hosted in the same web site as the Silverlight client? If not do you have the cross domain policy files setup correctly.
Assuming the WCF Test Client works. Open up fiddler and compare the request from your Silverlight client with that from the WCF Test Client. What is different?
Enable tracing on the server to see if there are any exceptions or warnings that might provide more insight to what is wrong.
Check your startup project to be sure you are starting a web project and not the Silverlight project. For more details see Troubleshooting Workflow Services / Silverlight on my blog

WCF Service calling another WCF service fails with web error 400 Bad Request

We have a web service that is called when user clicks save button on web form. The 'save' web service then makes a call into another web service (different machine). The call always fails and as far as I can tell does not even attempt to cross the network because the Fiddler traffic is empty. This problem only occurs when we call the second web service from the first web service. If we call the second web service straight from the client or on page load, it works. We are using WebHTTPBinding with REST type services.
I used the WCF trace to come up with the error 'Envelope Version 'EnvelopeNone (http://schemas.microsoft.com/ws/2005/05/envelope/none)' does not support adding Message Headers.', but I don't know how to resolve it.
Any suggestions?
Possible fixes:
Check #ServiceHost directive( in
. svc file) is set to
"WebServiceHostFactory" source
WebHttpBeahvior element is added in
the endpoint behavior source
Put ORDER information in the XML
schema Class source
Check that your Data Transfer objects are
serrializable source
Check if Skype installed and make sure it
doesn't overtake the port
source
Remove SOAP message header (it is not supported for REST
WCF) source

Silverlight WCF Service to Service calls

Question:
Are there known issues making calls to a service that calls another service from Silverlight?
Scenario:
I have the following 3 projects:
SilverlightClient - Silverlight project with a Button
SilverlightClient.Web - A web application that hosts the SilverlightClient.xap.
BackEnd - A different web application that hosts the FOO Service which does some special backend processing.
I have created a Silverlight WCF-Enabled web service in both SilverlightClient.Web and Backend. These are respectively SilverlightClientService and BackEndService.
From SilverlightClient.Web I add a service reference to BackEndService. I have a test ASPX page that I've written code that calls BackEndService successfully.
From SilverlightClient I add a service reference to SilverlightClient.Web's SilverlightClientService. If my SilverlightClientService returns plain data, such as a string, it works quite well.
The moment, however, that I change SilverlightClientService to call BackEndService, I get the following exception:
HTTP 415 - "The request failed with HTTP status 415: Unsupported Media Type."
I had an issue with 2 services not communicating. We finally figured out that using Cassini (the built in Visual Studio IIS) to host the ListenerService 'BackEnd' was causing the problem. Switching the project to start in a virtual directory of IIS allowed the two to communicate.
I was seeing : An error occurred while receiving the HTTP response to http://localhost:1484/MainListenerService.cs. This could be due to the service endpoint binding not using the HTTP protocol. This could also be due to an HTTP request context being aborted by the server (possibly due to the service shutting down). See server logs for more details. and this error:
The HTTP request was forbidden with client authentication scheme 'Anonymous'.
Are you using basicHttpBinding? Silverlight only supports basicHttpBinding but the default when you create a WCF service is wsHttpBinding. You should change that on your web.config before adding the reference on your Silverlight project. Check out this video from Tim Heuer: http://silverlight.net/learn/videos/all/how-to-consume-wcf-and-aspnet-web-services-in-silverlight/

Load balancing error with WCF service - NLB

UPDATE 3:
I created a Visual Studio 2008 test project and tried to create a service reference to shared site WCF service reference and received the following error:
There was an error downloading
'http://apps.mydomain/MyService.svc'.
The request failed with HTTP status
400: Bad Request. Metadata contains a
reference that cannot be resolved:
'http://apps.mydomain/MyService.svc'.
Content Type application/soap+xml;
charset=utf-8 was not supported by
service
http://apps.mydomain/MyService.svc'.
The client and service bindings may be
mismatched. The remote server returned
an error: (415) Cannot process the
message because the content type
'application/soap+xml; charset=utf-8'
was not the expected type 'text/xml;
charset=utf-8'.. If the service is
defined in the current solution, try
building the solution and adding the
service reference again.
UPDATE 2:
#Nick - I tried your suggestion of explictly setting the address of each endpoint with the fully qualified path of each server and I still get the same result.
Also, when I try to set the listenUri attribute with the shared site URL, I get a 400 bad request error instead of a 404 error.
UPDATE
After some additional research, there were some IIS configuration setting conflicts between http://apps1.mydomain and http://apps2.mydomain and was able to get past the "Server Application Unavailable" error.
Now I am getting a 404 error when I tried to browse to the shared site (http://apps.mydomain), but I am able to browse to the http://apps1.mydomain and http://apps2.mydomain service reference.
Original Problem
My companys uses Microsoft NLB to load balance traffic between our IIS servers. I recently deployed a WCF service on to each IIS 6 Windows Server 2003 Standard Edition SP1 servers. I received the following error when I tried to browse to the shared domain name using IE 7:
Server Application Unavailable The
web application you are attempting to
access on this web server is currently
unavailable. Please hit the "Refresh"
button in your web browser to retry
your request.
Administrator Note: An error message
detailing the cause of this specific
request failure can be found in the
application event log of the web
server. Please review this log entry
to discover what caused this error to
occur.
The consumer will point to the http://apps.mydomain to use the service but virtual domain is mapped to http://apps1.mydomain or http://apps2.mydomain. If I browse to the service on each server, I do not receive that error.
The service is currently using a anonymous basicHttpBinding.
Has anyone else experienced this issue?
History
Before this error started occurring, I received the following error when I broswed to all three domain name (http://apps.mydomain, http://apps1.mydomain, http://apps2.mydomain):
This collection already contains an
address with scheme http. There can
be at most one address per scheme in
this collection.
I used the ServiceHostFactory class to customize my .svc file to specify a custom service factory. Then I create our custom factory by inheriting from ServiceHostFactory and overriding as required.
public class MyFactory : ServiceHostFactory
{
protected override ServiceHost CreateServiceHost(Type serviceType, Uri[] baseAddresses)
{
return new ServiceHost(serviceType, baseAddresses[0]);
}
}
<%# ServiceHost Language="C#" Factory="MyFactory" Debug="true" Service="MyService" CodeBehind="~/App_Code/MyService.cs" %>
After some experimenting with different configurations for my WCF service and consuming application. I created a service reference to one of the working service references (http://apps1.mydomain or http://apps2.mydomain) in the consuming application. Then I changed the endpoint reference in the client configuration to point to the shared site WCF address (http://apps.mydomain) and I was able to consume and use the service.
I've had an issue before with WCF and load balancing where the servers had multiple Network cards with different IP addresses and WCF would just pic the first IP address it found. We had to explicitly set the IP address on each server's Service Definition so WCF would bind to the right one.