Unable to access remote WCF web service hosted on server - wcf

Hi I have deployed the WCF web service on the server machine. I am able to browse it in browser. but when i am going to add its service reference to my web application on development machine I am getting following detail error:
Metadata contains a reference that cannot be resolved:
'http://ServerMachineName:500/ITCAMSWebService_deploy/Services/Authentication.svc?wsdl'.
The WSDL document contains links that could not be resolved.
There was an error downloading 'http://ServerMachineName:500/ITCAMSWebService_deploy/Services/Authentication.svc?xsd=xsd0'.
The underlying connection was closed: An unexpected error occurred on a receive.
Unable to read data from the transport connection: An existing connection was forcibly closed by the remote host.
An existing connection was forcibly closed by the remote host
Metadata contains a reference that cannot be resolved: 'http://ServerMachineName:500/ITCAMSWebService_deploy/Services/Authentication.svc'.
Content Type application/soap+xml; charset=utf-8 was not supported by service
http://ServerMachineName:500/ITCAMSWebService_deploy/Services/Authentication.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.
Generated Service Model section in Web.config at server is as follows:
<system.serviceModel>
<services>
<service name="Authentication" behaviorConfiguration="Behavior_Authentication">
<host>
<baseAddresses>
<add baseAddress="http://ServerMachineName:500/ITCAMSWebService_deploy/Services/Authentication.svc"></add>
</baseAddresses>
</host>
<endpoint address="" contract="IAuthentication" binding="basicHttpBinding" bindingConfiguration="ITCAMSWebService.IAuthentication" />
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior>
<!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment -->
<serviceMetadata httpGetEnabled="true" />
<!-- To receive exception details in faults for debugging purposes, set the value below to true. Set to false before deployment to avoid disclosing exception information -->
<serviceDebug includeExceptionDetailInFaults="true" />
<dataContractSerializer maxItemsInObjectGraph="2147483646" />
</behavior>
</serviceBehaviors>
</behaviors>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" aspNetCompatibilityEnabled="true" />
</system.serviceModel>

Resolved !!! By adding Everyone user with full rights to C:\Windows\Temp on the server. IIS needs the rights to generate Metadata file in Temp folder on the server.

Please give ip address of your server in the address instead of ServerMachineName and also check the bindings of both client n server

Related

Debugging WCF in VS2015 using SSL

I have recently been asked to make changes to a wcf service which uses ssl. The developer who created the project no longer works for us. The problem I am having is that when I run it in visual studio 2015 I get an error pops up in a dialog box titled:
"Failed to add service. Service metadata may not be accessible. Make sure your service is running and exposing metadata"
The error details are:
Error: Cannot obtain Metadata from https://localhost:50257/AssignmentImport.svc If this is a Windows (R) Communication Foundation service to which you have access, please check that you have enabled metadata publishing at the specified address. For help enabling metadata publishing, please refer to the MSDN documentation at http://go.microsoft.com/fwlink/?LinkId=65455.WS-Metadata Exchange Error URI: https://localhost:50257/AssignmentImport.svc Metadata contains a reference that cannot be resolved: 'https://localhost:50257/AssignmentImport.svc'. An error occurred while making the HTTP request to https://localhost:50257/AssignmentImport.svc. This could be due to the fact that the server certificate is not configured properly with HTTP.SYS in the HTTPS case. This could also be caused by a mismatch of the security binding between the client and the server. The underlying connection was closed: An unexpected error occurred on a send. The handshake failed due to an unexpected packet format.HTTP GET Error URI: https://localhost:50257/AssignmentImport.svc There was an error downloading 'https://localhost:50257/AssignmentImport.svc'. The underlying connection was closed: An unexpected error occurred on a send. The handshake failed due to an unexpected packet format.
In the web.config file the service model is:
<system.serviceModel>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true"/>
<services>
<service name="NetiveApi.IisHost.TimesheetImport" behaviorConfiguration="metadatadiscov">
<endpoint name="TimesheetWs" binding="wsHttpBinding" bindingConfiguration="WsHttpBinding" contract="NetiveApi.IisHost.ITimesheetImport"/>
<endpoint name="mexHttpsBinding" binding="mexHttpsBinding" address="mex" contract="IMetadataExchange"/>
</service>
<service name="NetiveApi.IisHost.AssignmentImport" behaviorConfiguration="metadatadiscov">
<endpoint name="AssignmentWs" binding="wsHttpBinding" bindingConfiguration="WsHttpBinding" contract="NetiveApi.IisHost.IAssignmentImport"/>
<endpoint name="mexHttpsBinding" binding="mexHttpsBinding" address="mex" contract="IMetadataExchange"/>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="metadatadiscov">
<!-- To avoid disclosing metadata information, set the values below to false before deployment -->
<serviceMetadata httpGetEnabled="true" httpsGetEnabled="true"/>
<!-- To receive exception details in faults for debugging purposes, set the value below to true. Set to false before deployment to avoid disclosing exception information -->
<serviceDebug includeExceptionDetailInFaults="false"/>
<useRequestHeadersForMetadataAddress>
<defaultPorts>
<!-- Use your own port numbers -->
<!--<add scheme="http" port="8080" />-->
<add scheme="https" port="444"/>
</defaultPorts>
</useRequestHeadersForMetadataAddress>
</behavior>
</serviceBehaviors>
</behaviors>
<bindings>
<wsHttpBinding>
<binding name="WsHttpBinding">
<security mode="Transport">
<transport clientCredentialType="None"/>
</security>
</binding>
</wsHttpBinding>
</bindings>
Service Contract for assignment
[ServiceContract]
public interface IAssignmentImport
{
[OperationContract]
Acknowledgement ImportAssignment(string xml, string system, Guid authenticationToken);
}
Service Contract for timesheet
[ServiceContract]
public interface ITimesheetImport
{
[OperationContract]
Acknowledgement ImportTimesheet(string xml, string system, Guid authenticationToken);
[OperationContract]
string ApiActive();
}
I have read a number of articles about self signed certificates but they seem to suggest this is for use under IIS rather than IIS express in visual studio.
Any help and advice on this subject would be great.
Thanks
First thing you should check is whether you are able to browse the wsdl through https://localhost:50257/AssignmentImport.svc.
I don't think you can because of missing behavior configuration.
<service name="NetiveApi.IisHost.TimesheetImport" behaviorConfiguration="metadatadiscov">
Now name your service behavior which has overridden the default implementation of the metadata.
<behavior name="metadatadiscov" >
<!-- To avoid disclosing metadata information, set the values below to false before deployment -->
<serviceMetadata httpGetEnabled="true" httpsGetEnabled="true"/>
<!-- To receive exception details in faults for debugging purposes, set the value below to true. Set to false before deployment to avoid disclosing exception information -->
<serviceDebug includeExceptionDetailInFaults="false"/>
<useRequestHeadersForMetadataAddress>
<defaultPorts>
<!-- Use your own port numbers -->
<!--<add scheme="http" port="8080" />-->
<add scheme="https" port="444"/>
</defaultPorts>
</useRequestHeadersForMetadataAddress>
</behavior>
Now you should be able to browse the wsdl.
https://localhost:50257/AssignmentImport.svcIf not kindly post your service contract as well as Base address configuration.

WCF service is unavailable after app pool recycles

I'm working on a website that consumes a WCF service hosted in a different app pool, and every time the WCF service's app pool recycles I get a 503 when I'm using the website:
[WebException: The remote server returned an error: (503) Server Unavailable.]
System.Net.HttpWebRequest.GetResponse() +6440728
System.ServiceModel.Channels.HttpChannelRequest.WaitForReply(TimeSpan timeout) +55
[ServerTooBusyException: The HTTP service located at http://cr.genesis.dev/Genesis/RepositoryService.svc is unavailable. This could be because the service is too busy or because no endpoint was found listening at the specified address. Please ensure that the address is correct and try accessing the service again later.]
...
When I try to access the service directly in my web browser it gives me a 503 the first time, but then it works after that (presumably it's causing the application to start?) I'm wondering why the website isn't waking up the web service - even if I try loading a page several times I still get a 503...
I'm using Windsor WCF Integration if that makes any difference, using LifestylePerWebRequest for my client and LifestylePerThread for my service.
This is my config for the service:
<system.serviceModel>
<services>
<service name="Genesis.Repository.Service.RepositoryService" behaviorConfiguration="repositoryServiceBehaviour">
<host>
<baseAddresses>
<add baseAddress="http://cr.genesis.dev/Genesis/" />
</baseAddresses>
</host>
<endpoint name="basicHttpBinding"
address="RepositoryService.svc"
binding="basicHttpBinding"
contract="Genesis.Repository.Service.IRepositoryService" />
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="repositoryServiceBehaviour">
<!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment -->
<serviceMetadata httpGetEnabled="true" />
<!-- To receive exception details in faults for debugging purposes, set the value below to true. Set to false before deployment to avoid disclosing exception information -->
<serviceDebug includeExceptionDetailInFaults="false"/>
</behavior>
</serviceBehaviors>
</behaviors>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" aspNetCompatibilityEnabled="true" />
</system.serviceModel>
And the client:
<system.serviceModel>
<client>
<endpoint name="basicHttpBinding"
address="http://cr.genesis.dev/Genesis/RepositoryService.svc"
binding="basicHttpBinding"
contract="Genesis.Repository.Service.IRepositoryService" />
</client>
</system.serviceModel>
Any suggestions would be appreciated!
Looks like I was making it more complicated than it needed to be - I'd been getting exceptions saying it couldn't listen on http://+:80 which is why I'd played around with netsh permissions and made it listen on /Genesis.
Turns out I can just make it listen on / and specify .Hosted() when registering it with Windsor to tell it to let IIS host it (which is exactly how it was before I installed the WcfFacility!)
Lesson learned, sometimes you just have to go back to basics and things will work as intended!
If you found the "(503) Server Unavailable error" then first point of check is that server is running or not. For this go to the IIS and check the web site is on or off.

WCF IIS server configuration

I have Windows Server 2008 R2 with IIS7 on it. I deployed WCF service on it. When I specify WCF service address in browser (local or external machine) http://sbkisourcedev01/VCIndex/Calculator.svc?wsdl I am getting service description in browser. However when I am trying to add reference to the project to that service I am getting following error:
The document was understood, but it could not be processed.
- The WSDL document contains links that could not be resolved.
- There was an error downloading 'http://sbkisourcedev01/VCIndex/Calculator.svc?xsd=xsd0'.
- The underlying connection was closed: An unexpected error occurred on a receive.
- Unable to read data from the transport connection: An existing connection was forcibly closed by the remote host.
- An existing connection was forcibly closed by the remote host
Metadata contains a reference that cannot be resolved: 'http://sbkisourcedev01/VCIndex/Calculator.svc?wsdl'.
Content Type application/soap+xml; charset=utf-8 was not supported by service http://sbkisourcedev01/VCIndex/Calculator.svc?wsdl. 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.
I have this service running on Windows 7 and it is okay. So I believe there is something with my W2K8 IIS configuration settings.
Here is my config file:
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="basicHttpBindingConfig" />
</basicHttpBinding>
</bindings>
<behaviors>
<serviceBehaviors>
<behavior name="serviceBehavior">
<serviceMetadata httpGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="true"/>
</behavior>
</serviceBehaviors>
</behaviors>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
<services>
<service behaviorConfiguration="serviceBehavior"
name="WCFVCIndex.Calculator">
<endpoint address=""
binding="basicHttpBinding"
contract="WCFVCIndex.ICalculator"
bindingConfiguration="basicHttpBindingConfig" />
<endpoint address="mex"
binding="mexHttpBinding"
contract="IMetadataExchange" />
</service>
</services>
</system.serviceModel>
Thanks in advance.
The problem was with WCF identity permissions. The identity that is used for the application pool that hosts the WCF service must have full NTFS permissions on the %WINDIR%\temp folder. After changing that permission to my identity (LOCAL SERVICE) on C:\Windows\Temp I was able to add service reference to WCF service.
have you tried http://sbkisourcedev01/VCIndex/mex?

WCF Service client problem

I'm trying to create a client for a WCF service that I have hosted on IIS 5.1.I'm getting a strange problem: I can access the service through a browser just fine, I see the "You have created a service" page, but whenever I try running svcutil (as suggested by the same page)
svcutil.exe http://my.host.name/SampleService/SampleService.svc?wsdl
I get the following error:
Error: Cannot obtain Metadata from http://localhost.ms.com/SampleService/SampleS
ervice.svc?wsdl
If this is a Windows (R) Communication Foundation service to which you have acce
ss, please check that you have enabled metadata publishing at the specified addr
ess. For help enabling metadata publishing, please refer to the MSDN documentat
ion at http://go.microsoft.com/fwlink/?LinkId=65455.
WS-Metadata Exchange Error
URI: http://localhost.ms.com/SampleService/SampleService.svc?wsdl
Metadata contains a reference that cannot be resolved: 'http://localhost.ms.
com/SampleService/SampleService.svc?wsdl'.
The HTTP request is unauthorized with client authentication scheme 'Anonymou
s'. The authentication header received from the server was 'Negotiate'.
The remote server returned an error: (401) Unauthorized.
HTTP GET Error
URI: http://localhost.ms.com/SampleService/SampleService.svc?wsdl
There was an error downloading 'http://localhost.ms.com/SampleService/Sample
Service.svc?wsdl'.
The request failed with an empty response.
If you would like more help, type "svcutil /?"
What could be causing this problem?
EDIT: Could it be a problem with IIS itself? Incorrectly set permissions for example?
EDIT: Here's my web.config:
<?xml version="1.0"?>
<configuration>
<system.web>
<compilation debug="true" targetFramework="4.0" />
</system.web>
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="Basic">
<security mode="None"/>
</binding>
</basicHttpBinding>
</bindings>
<services>
<service name="DummyService2.SampleService"
behaviorConfiguration="DummyService2.SampleServiceBehavior">
<!-- Service Endpoints -->
<endpoint address="" binding="basicHttpBinding" contract="DummyService2.ISampleService"
bindingConfiguration="Basic" />
<endpoint address="mex" binding="basicHttpBinding" contract="IMetadataExchange"
bindingConfiguration="Basic" />
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="DummyService2.SampleServiceBehavior">
<!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment -->
<serviceMetadata httpGetEnabled="true"/>
<!-- To receive exception details in faults for debugging purposes, set the value below to true. Set to false before deployment to avoid disclosing exception information -->
<serviceDebug includeExceptionDetailInFaults="true"/>
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true"/>
</system.webServer>
</configuration>
I think that this is the relevant error:
The HTTP request is unauthorized with client authentication scheme 'Anonymous'.
The authentication header received from the server was 'Negotiate'.
Is the web service password protected or using integrated Windows authentication? If I remember correctly, svcutil can't log on with integrated authentication to a web service. When you use a browser it works just fine, becuase it handles the authentication in the background for intranet environments.
One option is to download and save the wsdl manually and then point svcutil to use the downloaded wsdl file to generate the classes. You probably have to download some files that are referenced by the wsdl too and edit the references.

WCF Metadata reference cannot be resolved

I am having an issue where I can't add a service reference in Visual Studio 2010 via a URL.
I have my HOST file setup to resolve http://mydomain.com locally, and setup my web.config file to reference this url. However when I go to add a service reference by URL I get the following error:
Metadata contains a reference that cannot be resolved: 'http://mydomain.com/myservice.svc?wsdl'.
The WSDL document contains links that could not be resolved.
There was an error downloading 'http://mydomain.com/myservice.svc?xsd=xsd0'.
The underlying connection was closed: An unexpected error occurred on a receive.
Unable to read data from the transport connection: An existing connection was forcibly closed by the remote host.
An existing connection was forcibly closed by the remote host
Metadata contains a reference that cannot be resolved: 'http://mydomain.com/myservice.svc'.
There was no endpoint listening at http://mydomain.com/myservice.svc that could accept the message. This is often caused by an incorrect address or SOAP action. See InnerException, if present, for more details.
The remote server returned an error: (404) Not Found.
The other URLS work fine:
http://mydomain.com/myservice.svc?wsdl and http://mydomain.com/myservice.svc
Here is my web.config file:
<?xml version="1.0"?>
<configuration>
<system.web>
<compilation debug="true" targetFramework="4.0" />
</system.web>
<system.serviceModel>
<services>
<!-- Note: the service name must match the configuration name for the service implementation. -->
<service name="FuncWS.Email" behaviorConfiguration="ServiceType" >
<!-- Add the following endpoint. -->
<endpoint address="myservice.svc" binding="webHttpBinding" contract="FuncWS.IEmail"></endpoint>
<!-- Note: your service must have an http base address to add this endpoint. -->
<endpoint contract="IMetadataExchange" binding="mexHttpBinding" address="mex" />
<host>
<baseAddresses>
<add baseAddress="http://mydomain.com"/>
</baseAddresses>
</host>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="ServiceType">
<!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment -->
<serviceMetadata httpGetEnabled="true"/>
<!-- To receive exception details in faults for debugging purposes, set the value below to true. Set to false before deployment to avoid disclosing exception information -->
<serviceDebug includeExceptionDetailInFaults="false"/>
</behavior>
</serviceBehaviors>
</behaviors>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
</system.serviceModel>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true"/>
</system.webServer>
</configuration>
The solution to this problem is that IIS needs to have rights to the C:\Windows\Temp folder. Without this it can't generate the meta data needed.