Service call failed in WCF through c# - c#

I have a simple client and server file but service call fails, and I don't know why. Also, I am not able to find the contract name in the dll file.
Client :
<endpoint address="http://localhost/SelfHostedServiceConsole"
binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_ISampleService1"
contract="SelfHostedService.ISampleService" name="BasicHttpBinding_ISampleService1" />
</client>
</system.serviceModel>
</configuration>
I am calling using runclient.cmd:
set local
TestClient admin
pause
Every time I run this I just get
Using self hosted service
Service call failed
Client code:
<client>
<endpoint address="localhost/SelfHostedServiceConsole"; binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_ISampleService1&‌​quot; contract="SelfHostedService.ISampleService" name="BasicHttpBinding_ISampleService1" />
</client>

Related

Updating Service References for specific endpoint

My server used to communicate only with WCF client, and I added an additional access from the web using REST API. So currently the service's web.config contains two endpoints (one for each):
<services>
<service name="Server.Service">
<endpoint address="" bindingConfiguration="BasicHttpBinding_IServWCF" binding="basicHttpBinding" contract="Server.IWCF" />
<endpoint address="api" behaviorConfiguration="WebBehave" binding="webHttpBinding" contract="Server.IREST" />
</service>
</services>
The WCF client bindings:
<bindings>
<basicHttpBinding>
<binding name="BasicHttpBinding_IServWCF" />
</basicHttpBinding>
</bindings>
<client>
<endpoint address="http://localhost:1862/ServWCF.svc"
binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IServWCF"
contract="WCFServ.IWCF" name="BasicHttpBinding_IServWCF" />
</client>
Everything works OK, and I can access the server's methods from both ways - WCF and HTTP requests.
The problem - I tried to use the Update Service References feature, but it fails. I get the following error message:
The client and service bindings may be mismatched. the remote server returned an error 415
When I remove the new endpoint - behaviorConfiguration="WebBehave", the update service reference works fine. Can I somehow configure the Update References to use a specific end point?
Thanks

deploy web application and web service remotely - 404 error

I created a web application and WCF web service in VS2010. It works fine locally. I want to deploy the web application and service to a test server. The application and service will be on the same server. I published the app and service to the server and created an Application Pool for the App, Paging. I added the application and service to the Site folder in IIS and converted them to applications.
When I try to access the application I get a 404 error. I believe it is because I need to start the web service. When it runs locally, I start the web service from a VS2010 project and then start the web application. Don't I also have to start the web service on the web server? How do I do that?
The application and web service folders are in the folders: C:\inetpub\wwwroot2\PagingService and C:\inetpub\wwwroot2\PagingTool. When accessing the web service I tried, http://localhost/PagingService/PagingService.Paging.svc, I get the error:
The authentication schemes configured on the host ('Ntlm') do not allow those configured on the binding 'WSHttpBinding' ('Anonymous').
The application and web service works fine on my local machine, do I have to change the authentication because it is on a web server? The OS is Windows Server 2008.
This is my app.config file for my connection:
<services>
<service name="PagingService.Paging" behaviorConfiguration="SimpleServiceBehavior">
<endpoint address="" binding="wsHttpBinding" bindingConfiguration="WSHttpBinding_IPaging" contract="PagingService.IPaging">
<identity>
<dns value="localhost" />
</identity>
</endpoint>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
<host>
<baseAddresses>
<add baseAddress="http://localhost:8732/Design_Time_Addresses/PagingService/Service1/" />
</baseAddresses>
</host>
</service>
</services>
<bindings>
<wsHttpBinding>
<binding name="WSHttpBinding_IPaging"
maxReceivedMessageSize="20000000"
maxBufferPoolSize="20000000"
sendTimeout="00:25:00">
<readerQuotas maxDepth="32"
maxArrayLength="200000000"
maxStringContentLength="200000000"/>
</binding>
</wsHttpBinding>
</bindings>
Any suggestions would be appreciated.
Thanks.
In your IIS make sure you have Anonymous Authentication set as "Enabled" for your web service.

Calling web service from Windows Form and jQuery

I have an existing web WCF web service which can be called by a Windows form via a proxy.
I wish to also be able to call this service from jQuery.
I am following the following article: http://www.codemag.com/Article/1308041
However, I am stuck because the article says to add the following code to the web.config of the service:
<services>
<service
behaviorConfiguration="ProductServiceBehavior"
name="ProductServiceHost.ProductService">
<endpoint
address=""
binding="basicHttpBinding"
contract="ProductServiceHost.IProductService" />
</service>
</services>
My config file already has this for my service:
<service
behaviorConfiguration="MyApp.EndPoint.Services.TrainingServiceBehavior"
name="MyApp.EndPoint.Services.TrainingService">
<endpoint
address="" binding="wsHttpBinding"
contract="MyApp.EndPoint.Services.Interface.ITrainingService"
name="wsHttp"
bindingConfiguration="wsHttpBindingConfiguration">
<identity>
<dns value="localhost" />
</identity>
</endpoint>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
</service>
I've tried replacing the binding with the basicHttpBinding, but I then get errors when calling the service from my Windows form, such as "The remote server returned an error: (415) Unsupported Media Type."
Should my service have both of the above bindings?
Basically, my changes fail at the step: You should run your existing application at this point to ensure that everything still works.
Can anyone point me in the right direction?
I added the following to the config file:
<service
behaviorConfiguration="MyApp.EndPoint.Services.TrainingServiceBehavior"
name="MyApp.EndPoint.Services.TrainingService">
<endpoint
address=""
binding="basicHttpBinding"
contract="MyApp.EndPoint.Services.Interface.ITrainingService" />
</service>
I also added the following decoration:
[WebInvoke(Method = "POST",
BodyStyle = WebMessageBodyStyle.WrappedRequest,
ResponseFormat = WebMessageFormat.Json,
RequestFormat = WebMessageFormat.Json)]
However, my Windows form app now gets the following error when it calls the service:
The server did not provide a meaningful reply; this might be caused by a contract mismatch, a premature session shutdown or an internal server error.
The error is presumably because I have two services in the config file with the same name. If I give the new service a new name, would I have to create a new method?
I'm trying to use the same method, but this seems to be impossible.
I think you can leave your current configuration as it is. The changes made in the article are made to a very basic configuration in order to make the configuration of the existing service explicit (by stating the binding, the contract and the behavior). Your configuration already states the service explicit.
What you should do is add a new configuration for jquery to use as described in the article: add a new behavior and add a new endpoint.

WCF Service - service in separate class library

This is my project diagram:
MyWCFService
(...)
web.config
Friends.Implementation
Friends.svc
Friends.svc.cs
Friends.Contract
IFriends.cs
My endpoint of service:
<service behaviorConfiguration="ServiceBehaviour" name="Friends.Implementation.Friends">
<endpoint address="" behaviorConfiguration="web" binding="webHttpBinding" contract="Friends.Contract.IFriends" />
</service>
My question is: How can I call this service? When I had that service in "Service" folder in MyWCFService project, it was easy - just localhost:XX/Services/Friends.svc.
And now, how can I run it, if everything is in separate class libraries?
Regards
You can create a Services folder in your website root and paste the .svc file there, or you can use service activation:
<configuration>
<system.serviceModel>
<serviceHostingEnvironment>
<serviceActivations>
<add service="Friends.Implementation.Friends"
relativeAddress="Services/Friends.svc"/>
</serviceActivations>
</serviceHostingEnvironment>
</system.serviceModel>
</configuration>

How do you add a WCF service reference with a fixed port?

I have a WCF service being hosed by a Windows Service with this in the app.config
<services>
<service behaviorConfiguration="serviceBehavior" name="AgileServer.AgileService">
<endpoint address="AgileService" binding="basicHttpBinding" name="basicHttp" contract="AgileServer.AgileService" />
<endpoint binding="mexHttpBinding" name="mex" contract="IMetadataExchange" />
<host>
<baseAddresses>
<add baseAddress="http://localhost:24453/AgileService" />
</baseAddresses>
</host>
</service>
When I try to add a service reference to my service (by clicking "Discover" in the "Add Service Reference" prompt), the URI shows up as http://localhost:33908/AgileService.svc I want my service to use http://localhost:24453/AgileService as the URI. How can I accomplish this?
You need to
have the WCF service in your Windows service up and running
do not click on Discover, but instead type in / paste in the URL you want to connect to - either use the base address (http://localhost:24453/AgileService) or the MEX endpoint's address (http://localhost:24453/AgileService/mex)
Doing this will connect to the URL defined, and the service metadata will be retrieved and used to create a client-side proxy for the service.
Just as a side-note: your actual service URL will be:
http://localhost:24453/AgileService/AgileService
made up of your base address (http://localhost:24453/AgileService) plus the relative address on the endpoint (AgileService).

Categories

Resources