WCF: Updating Service Reference - asp.net

I have an issue with updating (also tried deleting and adding) service reference of a modified WCF service in ASP.NET website project using "Add Service Reference" feature provided by VS 2010. It doesn't create the Reference.cs properly as it used to before changes. I verified my service configuration in the web.config, the endpoint seems to be properly configured with mexhttpbinding.
<service behaviorConfiguration="ServiceBehavior" name="Services.XyzService">
<endpoint address="" binding="wsHttpBinding" contract="Services.IXyzService">
<identity>
<dns value="localhost"/>
</identity>
</endpoint>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
</service>
<behavior name="ServiceBehavior">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="false" />
</behavior>
Svc file also seems to be ok!!
<%# ServiceHost Language="C#" Debug="true" Service="Services.XyzService"%>
Any idea?

Related

How to host WCF if contracts,implementation and host are separate assembly

I have downloaded a layered sample from Codeplex from this link: https://layersample.codeplex.com/releases/view/107797
This contain a WCF service with this structure:
service contract library
service implementation library
web host project
Question: in the web host project, there is no .SVC file and it only contains configuration in the web.config file.
Can anyone guide me how it works or how I could consume/add service reference in a client application/how to host this on IIS.
This is the web.config file :
<system.serviceModel>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true">
<serviceActivations>
<add factory="System.ServiceModel.Activation.ServiceHostFactory"
relativeAddress="./LeaveService.svc"
service="LeaveSample.Services.LeaveService" />
<add factory="System.ServiceModel.Activities.Activation.WorkflowServiceHostFactory"
relativeAddress="./LeaveWorkflowService.svc"
service="LeaveSample.Workflows.LeaveWorkflowService" />
</serviceActivations>
</serviceHostingEnvironment>
<services>
<service name="LeaveSample.Services.LeaveService"
behaviorConfiguration="DefaultServiceBehavior">
<endpoint name="basicHttpLeaveService"
address=""
binding="basicHttpBinding"
contract="LeaveSample.Services.Contracts.ILeaveService" />
<endpoint
address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
</service>
<service name="LeaveWorkflowService">
<endpoint name="basicHttpWorkflowService"
address=""
binding="basicHttpBinding"
contract="ILeaveWorkflowService" />
<endpoint
address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="DefaultServiceBehavior">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="true" />
</behavior>
<behavior name="">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="true" />
<sqlWorkflowInstanceStore connectionStringName="workflowStore"
hostLockRenewalPeriod="00:00:30"
runnableInstancesDetectionPeriod="00:00:05"
instanceCompletionAction="DeleteAll"
instanceLockedExceptionAction="AggressiveRetry"
instanceEncodingOption="GZip" />
<workflowUnhandledException action="Cancel"/>
<dataContractSerializer maxItemsInObjectGraph="2147483647" />
</behavior>
</serviceBehaviors>
</behaviors>
<extensions>
<behaviorExtensions></behaviorExtensions>
</extensions>
<tracking>
<profiles></profiles>
</tracking>
</system.serviceModel>
Thank you
The project you downloaded is using "fileless activation":
<serviceActivations>
<add factory="System.ServiceModel.Activation.ServiceHostFactory"
relativeAddress="./LeaveService.svc"
service="LeaveSample.Services.LeaveService" />
<add factory="System.ServiceModel.Activities.Activation.WorkflowServiceHostFactory"
relativeAddress="./LeaveWorkflowService.svc"
service="LeaveSample.Workflows.LeaveWorkflowService" />
</serviceActivations>
The above portion of the configuration file defines two service activation endpoints, without having to have a physical .svc file.
It is hosted and consumed like any other WCF service using IIS - the only difference is there is no .svc file.
File-less activation was one of several WCF features introduced with WCF 4.0. You can read about it (and the other features) here - A Developer's Introduction to to Windows Communication Foundation 4.

wcf nettcpbinding An existing connection was forcibly closed by the remote host

Development Environment:
Services are hosted under IIS/WAS
I have four services developed on my local development. All four of them are working fine when I am accessing them from asp.net application. I am using net.tcp protocol to connect. I have specified net.tcp as allowed protocol at site level and at virtual directory level. All three services related to tcp are started.
In application web.config from which I am able to connect to services, I am using impersonation
But when I try to connect to the services by specifying net.tcp url in the Add service project of wcftestclient. I am not able to connect. With same configuration for two other services, I am able to connect to those two other services.
Test Server:
I even deployed on a Test Server. Even there I am facing same issue. I can connect to same two services using net.tcp url. But other two gives error. One of which's config is listed below. on Server I even removed allowed users part to make it run for all users.
Error I am getting is as follows.
Error: Cannot obtain Metadata from net.tcp://localhost/servicesdev/SalesPersonService.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: net.tcp://localhost/servicesdev/SalesPersonService.svc Metadata contains a reference that cannot be resolved: 'net.tcp://localhost/servicesdev/SalesPersonService.svc'. The socket connection was aborted. This could be caused by an error processing your message or a receive timeout being exceeded by the remote host, or an underlying network resource issue. Local socket timeout was '00:05:00'. An existing connection was forcibly closed by the remote host
Following is config section.
<services>
<service behaviorConfiguration="ServiceBehavior" name="WCFServiceLibrary.SalesPersonService">
<endpoint address="" binding="wsHttpBinding" contract="WCFServiceLibrary.ISalesPersonService" />
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
<endpoint address="mex" binding="mexTcpBinding" contract="IMetadataExchange" />
<endpoint address="basic" binding="basicHttpBinding" contract="WCFServiceLibrary.ISalesPersonService" />
<endpoint address="net.tcp://localhost/servicesdev/SalesPersonService.svc" binding="netTcpBinding" contract="WCFServiceLibrary.ISalesPersonService" listenUriMode="Explicit" />
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="ServiceBehavior">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="false" />
</behavior>
</serviceBehaviors>
</behaviors>
<system.web>
<compilation targetFramework="4.0" debug="true" />
<pages controlRenderingCompatibilityVersion="3.5" clientIDMode="AutoID" />
<identity impersonate="true" />
<authorization>
<allow users="myuser" />
</authorization>
</system.web>
Thanks,
BMP
You are specifying a relative address for mex, without giving a base address. Try giving a base address as shown in example below. the relative address for mex should work then
<host>
<baseAddresses>
<add baseAddress="net.tcp://localhost/servicesdev/SalesPersonService.svc"/>
</baseAddresses>
</host>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
<endpoint address="" binding="wsHttpBinding" contract="WcfServiceLibrary1.ISalesPersonService" />
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
<endpoint address="mex" binding="mexTcpBinding" contract="IMetadataExchange" />
<endpoint address="basic" binding="basicHttpBinding" contract="WcfServiceLibrary1.ISalesPersonService" />
<endpoint address="" binding="netTcpBinding" contract="WcfServiceLibrary1.ISalesPersonService" />

Value cannot be null. Parameter name: context

I have a WCF webservice which I am struggling to get to successfully run using netTcpBinding.
The error I am receiving is
Value cannot be null.
Parameter name: context
Amongst the first search results that I received regarding this error message was the following post that suggests that this error occurs because WCF doesn't support enumerations (which my service does contain).
However having spent some time in creating another test WCF service I have been able to successfully serve responses that contained enumerations through my webservice which seems to contradict what that post is saying.
Here is how my service definition looks.
<service name="Implementations.CourseService" behaviorConfiguration="metadataBehavior">
<endpoint address="mex" binding="mexTcpBinding" contract="IMetadataExchange" />
<endpoint address="/CourseService.svc" binding="wsHttpBinding" contract="Contracts.ICourseService" />
<endpoint address="" binding="netTcpBinding" contract="Contracts.ICourseService">
<identity>
<dns value="localhost" />
</identity>
</endpoint>
<host>
<baseAddresses>
<add baseAddress="net.tcp://localhost:808/CourseService.svc" />
</baseAddresses>
</host>
</service>
<serviceBehaviors>
<behavior name="metadataBehavior" >
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="true" />
</behavior>
</serviceBehaviors>
<netTcpBinding >
<binding name="tcpBinding" />
</netTcpBinding>
and this is the end result of invoking this service.
Any help would be immensely appreciated. I will also regularly check this post so if anyone needs any further information that I may not have provided please do ask, as I'm not really sure what's pertinent and what's not.

Webservice over SSL endpoint not found with 404

I've got a webservice up and running and through the browser I can reach it and see it's up and running. Also without https I can make calls to the webservice.
To make calls at the moment I'm using a small console application to test and see the results.
Server side my web.config is as following:
The service section
<services>
<service name="Website.mynamespace.Service1">
<endpoint address="/service.svc" behaviorConfiguration="" binding="wsHttpBinding" contract="SomeDLLFile.Anothernamespace.Services.Proxy.Interface1" ></endpoint>
<endpoint address="/service.svc" behaviorConfiguration="" binding="wsHttpBinding" contract="SomeDLLFile.Anothernamespace.Services.Proxy.Interface1" bindingConfiguration="myBinding" />
<endpoint address="mex" binding="wsHttpBinding" contract="IMetadataExchange"/>
</service>
<service name="Website.mynamespace.Service2">
<endpoint address="/service.svc" behaviorConfiguration="" binding="wsHttpBinding" contract="SomeDLLFile.Anothernamespace.Services.Proxy.Interface2" ></endpoint>
<endpoint address="/service.svc" behaviorConfiguration="" binding="wsHttpBinding" contract="SomeDLLFile.Anothernamespace.Services.Proxy.Interface2" bindingConfiguration="myBinding" />
<endpoint address="mex" binding="wsHttpBinding" contract="IMetadataExchange"/>
</service>
</services>
The used binding
<wsHttpBinding>
<binding name="myBinding">
<security mode="Transport">
<transport clientCredentialType="None"/>
</security>
</binding>
</wsHttpBinding>
On the client side (my console application) i've added an service reference to my webservice. This way I'm able to make calls over HTTP. However when using HTTPS i'm getting an error saying the following
"There was no endpoint listening at https://test.mywebsite.nl/service.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 app.config from my console application looks like this;
<client>
<endpoint address="https://test.mywebsite.nl/service.svc"
binding="basicHttpBinding"
bindingConfiguration="BasicHttpBinding_IProxyInterface1"
contract="Service.IProxyInterface1"
name="BasicHttpBinding_IProxyClientInterface" />
<endpoint address="https://test.mywebsite.nl/service.svc"
binding="basicHttpBinding"
bindingConfiguration="BasicHttpBinding_IProxyInterface2"
contract="Service.IProxyInterface2"
name="BasicHttpBinding_IProxyInterface2" />
</client>
<behaviors>
<serviceBehaviors>
<!--
Step 2. Inside a <serviceBehaviors> section, add
a name attribute in the <behaviors> element that
matches the behaviorConfiguration attribute in the
<service> element above.
-->
<behavior name="">
<serviceMetadata httpGetEnabled="true" httpGetUrl=""/>
<serviceDebug httpHelpPageEnabled="true" includeExceptionDetailInFaults="true" />
</behavior>
</serviceBehaviors>
</behaviors>
When i'm looking at the inner exception I'm looking at an 404-error. I've tried various suggestion from other topics on SO and also articles at MS, but I must be missing something since i'm still represented with the same error. Anybody any idea what I'm doing wrong here?
Got the issue solved thanks to this topic here on SO.
The problem was in the service name, so I combined the endpoints to both contracts in one service definition. I also changed the wsHttpBinding to an basicHttpBinding.
I had something similar and installed a Self Certified SSL certificate in IIS. Try:
http://weblogs.asp.net/scottgu/archive/2007/04/06/tip-trick-enabling-ssl-on-iis7-using-self-signed-certificates.aspx
Obviously you will need to buy a proper certificate when you come to deploy into your production environment.

Unable to Connect to WCF Service from MVC Site

I've written a WCF service that is hosted within a Windows Service on my home computer. I then wrote an MVC3 site that is attempting to connect to the service. The MVC3 site is hosted on godaddy servers. I opened the ports on my firewall correctly because I am able to access the service description site from a computer on a different network, and I even had a friend connect to the web service from a console app running on his computer, and it worked perfectly. However, when I attempt to call the web service from my MVC3 site it throws the following error:
There was no endpoint listening at http://myExternIpAddress:8000/MyService/service that could accept the message. This is often caused by an incorrect address or SOAP action. See InnerException, if present, for more details.
Here is the important part of the app.config for the service:
<services>
<service name="MyService.MyService"
behaviorConfiguration="MyServiceBehavior" >
<host>
<baseAddresses>
<add baseAddress="http://localhost:8000/MyService/service" />
</baseAddresses>
</host>
<endpoint address=""
binding="basicHttpBinding"
contract="MyService.IMyService" />
<endpoint address="mex"
binding="mexHttpBinding"
contract="IMetadataExchange" />
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="MyServiceBehavior">
<serviceMetadata httpGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="true"/>
</behavior>
</serviceBehaviors>
</behaviors>
and here is the service section of the web.config for the MVC3 site
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="BasicHttpBinding_IMyService" />
</basicHttpBinding>
</bindings>
<client>
<endpoint address="http://myExternalIpAddress:8000/MyService/service"
binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IMyService"
contract="LocalService.IMyService" name="BasicHttpBinding_IMyService" />
</client>
<behaviors>
<serviceBehaviors>
<behavior name="">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="false" />
</behavior>
</serviceBehaviors>
</behaviors>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
</system.serviceModel>
Thanks for any help that you can provide!
I would contact GoDaddy for support. If the WCF service works from your friends machine - it is likely a hosting environment issue.

Resources