Silverlight WCF service not working when deployed - c#

I have a WCF service method in a Silverlight application that inserts some data into a SQL Server database deployed on a shared GoDaddy server. Some of the methods work, and some do not, but all of them work when the application is run locally (with a local database). I get the generic "The remote server returned an error: NotFound", and I can't seem to get any more info. When I run the method directly from the service class (not through the service reference), it works correctly. Here is the service part of my web.config:
<system.serviceModel>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" />
<behaviors>
<serviceBehaviors>
<behavior name="default">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="true" />
<dataContractSerializer maxItemsInObjectGraph="6553600" />
</behavior>
</serviceBehaviors>
</behaviors>
<bindings>
<basicHttpBinding>
<binding name="BasicHttpBinding_IncreasedBuffer"
maxBufferSize="2147483647" maxBufferPoolSize="2147483647"
maxReceivedMessageSize="2147483647">
<readerQuotas maxBytesPerRead="2147483647" maxDepth="2147483647"
maxArrayLength="2147483647" maxNameTableCharCount="2147483647"/>
</binding>
</basicHttpBinding>
</bindings>
<services>
<service name="GreekTools.Services.DataService"
behaviorConfiguration="default">
<endpoint address="" binding="basicHttpBinding"
bindingConfiguration="BasicHttpBinding_IncreasedBuffer"
contract="GreekTools.Contracts.IDataService" />
<endpoint address="mex" binding="mexHttpBinding"
contract="IMetadataExchange" />
</service>
</services>
</system.serviceModel>
Any ideas?

Could it be that you have an older version of the dll deployed on the server side. That would explain why some work and some do not.
If this is not the case, is there any pattern in what works and what does not?

This is usually the case when you attempt to do a request on a url that does not exist. For example, you expect a service to be at http://hostname/path/Service.svc but it actually lives at http://hostname/Service.svc.
Your best course of action is to download a web debugging tool (Fiddler is a good choice) and check the actual requests that are sent from your Silverlight client to your web server. Very probably you'll see some problem with a url path that's incorrect.

Related

Problem with configuring HTTPS on my WCF service

I am trying to add transport security layer to my WCF service. But after following all the instructions i still get error "Could not find a base address that matches scheme https for the endpoint with binding BasicHttpBinding. Registered base address schemes are [http]."
Already did all needed configurations in IIS Manager and add need code in web.config but i still have a feeling i am missing something
web.config:
<system.serviceModel>
<services>
<service name="MyNameSpace.MyService" behaviorConfiguration="secureBehavior">
<endpoint address="" binding="basicHttpBinding" bindingConfiguration="secureHttpBinding" contract="MyNameSpace.IMyService" />
<endpoint address="mex" binding="mexHttpsBinding" contract="IMetadataExchange" />
</service>
</services>
<bindings>
<basicHttpBinding>
<binding name="secureHttpBinding">
<security mode="Transport">
<transport clientCredentialType="None" />
</security>
</binding>
</basicHttpBinding>
</bindings>
<behaviors>
<serviceBehaviors>
<behavior name="secureBehavior">
<serviceMetadata httpGetEnabled="true" httpsGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="false" />
</behavior>
</serviceBehaviors>
</behaviors>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
</system.serviceModel>
There is no problem with your present configuration, configure an https endpoint and it uses Transport security mode. One more thing we need to do is configuring an https binding address in IIS binding module. Like below.
It locates in the IIS site binding module.
Then we could use the above https service address to access it.
https://IP:4431/Service1.svc (service base address)
Feel free to let me know if the problem still exists.

Can we host WCF service on different port if created in web application?

I have a WCF service in the web application. Service and application are running fine. Web app address is localhost:53536 and service address is localhost:53536/Mobile/MobileService.svc. These are duplex services and I am consuming these service on the different application. Here is my configuration
<behaviors>
<serviceBehaviors>
<behavior name="" >
<serviceMetadata httpGetEnabled="true" httpsGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="false" />
</behavior>
</serviceBehaviors>
</behaviors>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true"
multipleSiteBindingsEnabled="true" />
<bindings>
<wsDualHttpBinding>
<binding name="MobileServiceBinding" closeTimeout="00:00:05" openTimeout="00:00:05">
<readerQuotas maxDepth="32" maxStringContentLength="5242880" maxArrayLength="16384" maxBytesPerRead="4096" maxNameTableCharCount="16384" />
</binding>
</wsDualHttpBinding>
</bindings>
<services>
<service name="Asm.As.PerformanceMonitor.Web.Mobile.MobileService" >
<endpoint address="" binding="wsDualHttpBinding" bindingConfiguration="MobileServiceBinding" contract="Asm.As.PerformanceMonitor.Web.Mobile.IMobileService" />
</service>
</services>
As you can see the address is empty. When I add address like http://localhost:1212
It's not working. An error comes refused to connect. Is there any way to host service on a different port or service has different address along with the application? Please note that service will be hosted with the web application.

WCF call returning 404

So I have a WCF service that calls another WCF service. I'm trying to debug the first service, so I attempted to run it. It fails with a
There was no endpoint listening at http://<host>/ConfigurationService/ConfigurationService.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 inner exception is
{"The remote server returned an error: (404) Not Found."}
Reference:
[System.ServiceModel.OperationContractAttribute(Action="http://tempuri.org/IConfigurationService/GetGlobalConfigurationGroup", ReplyAction="http://tempuri.org/IConfigurationService/GetGlobalConfigurationGroupResponse")]
ConfigurationGroup GetGlobalConfigurationGroup();
Taking that exact endpoint and putting it in a browser works. Taking it and putting it in WCFTestClient works. This code is already running in production, so I don't know what I'm doing wrong. I debug into the call and I see it's being sent as a POST instead of a GET. I'm assuming that's the culprit, but I have no idea on how to fix it or why it's magically different. I've looked at WCF method sending POST instead of GET and the link in that answer, but I don't understand it, couldn't get it to work, and the class that extends it is a generated class and won't debug into it either.
I put on failure request logging on the Configuration service, which logs something if I go to a bad location (ConfigurationService.svc1) but not when calling this.
<system.serviceModel>
<client>
<endpoint address="http://<host>/SecurityService/SecurityService.svc"
behaviorConfiguration="defaultBehavior" binding="basicHttpBinding"
bindingConfiguration="defaultHttpBinding" contract="Service.ISecurityService"
name="SecurityService" />
<endpoint address="http://<host>/ConfigurationService/ConfigurationService.svc"
behaviorConfiguration="defaultBehavior" binding="basicHttpBinding"
bindingConfiguration="defaultHttpBinding" contract="Service.IConfigurationService"
name="ConfigurationService" />
</client>
<bindings>
<basicHttpBinding>
<binding name="defaultHttpBinding" closeTimeout="00:10:00" openTimeout="00:10:00"
receiveTimeout="00:10:00" sendTimeout="00:10:00" maxReceivedMessageSize="2147483647" />
</basicHttpBinding>
</bindings>
<behaviors>
<endpointBehaviors>
<behavior name="defaultBehavior">
<dataContractSerializer ignoreExtensionDataObject="true" maxItemsInObjectGraph="2147483647" />
</behavior>
</endpointBehaviors>
<serviceBehaviors>
<behavior>
<!-- 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="true"/>
</behavior>
</serviceBehaviors>
</behaviors>
<protocolMapping>
<add binding="basicHttpsBinding" scheme="https" />
</protocolMapping>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
</system.serviceModel>
Config for Configuration Service:
<system.serviceModel>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true"/>
<services>
<service name="ConfigurationService" behaviorConfiguration="defaultBehavior">
<endpoint address="" binding="basicHttpBinding" bindingConfiguration="defaultHttpBinding"
contract="IConfigurationService"/>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
</service>
</services>
<bindings>
<basicHttpBinding>
<binding name="defaultHttpBinding" maxReceivedMessageSize="2147483647" openTimeout="00:10:00" closeTimeout="00:10:00" receiveTimeout="00:10:00" sendTimeout="00:10:00">
<readerQuotas maxStringContentLength="2147483647" maxArrayLength="20971520"/>
</binding>
</basicHttpBinding>
</bindings>
<behaviors>
<serviceBehaviors>
<behavior name="defaultBehavior">
<dataContractSerializer maxItemsInObjectGraph="2147483647"/>
<serviceMetadata httpGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="true"/>
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
Edit: I've noticed that it only exhibits this behavior when running a web project.
Try using Data Contracts in the service that you are trying to call.
https://msdn.microsoft.com/en-us/library/ms733127%28v=vs.110%29.aspx
Here a brief explanation about what they are and how they works.
I think that this is the error because of your error 'OperationContractAttribute'
Maybe is only the ServiceContract.
I hope this helps
In a multi-process environment where services are distributed and applications using those services are communicating via WCF, service contracts must be serialize-able. The easiest way to ensure serialization of contract objects is to decorate them with data contracts attributes as described here: https://msdn.microsoft.com/en-us/library/ms733127%28v=vs.110%29.aspx
Without proper serialization your services will still work under some conditions and unless you're attached to all your relevant processes while debugging you won't see any error thrown. Even logging will sometimes fail to show anything (or at least anything useful).
This likely isn't a configuration problem since you're using dataContractSerializer. Decorate your service contract classes so they can be serialized over WCF.
I once had this problem. Turns out I had the wrong address for the service in the configuration of my web project.

Unable to access WCF service using NET.TCP binding

I already asked a similar question here: Unable to add service client for a net.tcp WCF service. The problem was solved at that time. But now the same error is coming up. My configuration of WCF service is same as that of previous question. I am again posting it here:
<system.serviceModel>
<services>
<service name="CoreService.Service1" behaviorConfiguration="beh1">
<host>
<baseAddresses>
<add baseAddress="net.tcp://localhost/Service1.svc/mex" />
</baseAddresses>
</host>
<endpoint
binding="netTcpBinding"
bindingConfiguration="ultra"
contract="CoreService.IAccountService"/>
<endpoint
binding="netTcpBinding"
bindingConfiguration="ultra"
contract="CoreService.IBoardService"/>
<endpoint
binding="netTcpBinding"
bindingConfiguration="ultra"
contract="CoreService.ICategoryService"/>
<endpoint
address="mex"
binding="mexTcpBinding"
contract="IMetadataExchange"/>
</service>
</services>
<bindings>
<netTcpBinding>
<binding name="ultra"
maxBufferPoolSize="2147483647"
maxBufferSize="2147483647"
maxReceivedMessageSize="2147483647"
portSharingEnabled="false"
transactionFlow="false"
listenBacklog="2147483647"
sendTimeout="00:01:00">
<security mode="None">
<message clientCredentialType="None"/>
<transport protectionLevel="None" clientCredentialType="None"/>
</security>
<reliableSession enabled="false"/>
</binding>
</netTcpBinding>
</bindings>
<behaviors>
<serviceBehaviors>
<behavior name="beh1">
<serviceMetadata httpGetEnabled="false" />
<serviceDebug includeExceptionDetailInFaults="True" />
<dataContractSerializer maxItemsInObjectGraph="65536" />
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
The error is:
The URI prefix is not recognized. Metadata contains a reference that
cannot be resolved: 'net.tcp://localhost/Service1.svc'. Could not
connect to net.tcp://localhost/Service1.svc. The connection attempt
lasted for a time span of 00:00:02.0051147. TCP error code 10061: No
connection could be made because the target machine actively refused
it 127.0.0.1:808. No connection could be made because the target
machine actively refused it 127.0.0.1:808 If the service is defined in
the current solution, try building the solution and adding the service
reference again.
After the problem was solved, I didn't made any changes to the configuration and after some days it started showing that error again. I tried everything but nothing worked. Please help!
UPDATE: I am also able to access it using HTTP through my browser but unable to access using "Add Service Reference" option through net.tcp protocol.
Finally with the help of this link: http://rohitguptablog.wordpress.com/2011/06/16/configuring-wcf-service-with-nettcpbinding/, I figured out what was going wrong. Actually I missed the third step in above link. The Net.Tcp services were not running.

Web service contains an empty service tag

I created a WCF service.
In the WSDL I can't see the URL and PORT that the service should bind on.
All I see is:
<wsdl:service name="SimpleWebService"/>
Any idea what am I doing wrong? maybe something in the web.config?
<system.serviceModel>
<client />
<bindings>
<webHttpBinding>
<binding closeTimeout="00:10:00" openTimeout="00:10:00" receiveTimeout="00:10:00" sendTimeout="00:10:00" maxBufferSize="2147483647" maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647">
<readerQuotas maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="2147483647" />
</binding>
</webHttpBinding>
</bindings>
<services>
<service name="WS.OS.SimpleWS" behaviorConfiguration="myServiceBehavior">
<endpoint name="webHttpBinding" address="" binding="webHttpBinding" contract="WS.OS.SimpleWS" behaviorConfiguration="webHttp" />
<endpoint name="mexHttpBinding" address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="myServiceBehavior">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="false" />
</behavior>
</serviceBehaviors>
<endpointBehaviors>
<behavior name="webHttp">
<webHttp />
</behavior>
</endpointBehaviors>
</behaviors>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
</system.serviceModel>
Creating an endpoint with webHttpBinding creates a REST endpoint. REST endpoints does not have wsdl. In your case you see wsdl generated because you have included the metadata behavior. You will have an endpoint listed in WSDL only for SOAP endpoints. This is a good blog post which helps you to understand this better : http://blogs.msdn.com/b/carlosfigueira/archive/2012/03/26/mixing-add-service-reference-and-wcf-web-http-a-k-a-rest-endpoint-does-not-work.aspx
Looking at the question, and the config, I'm assuming (we all know where that leads) that your service is hosted in IIS. So given the address of "" and no port given, you will have to look in your IIS settings to find the site and the port on which the service is open. The defualt for http is 80 and https is 443.
So quick example, if your service is on the "Default Website" of the IIS then your service will probably be at:
http://YourServer/YourService/YourService.svc
If there is a web application that is hosted on there that is under a specificly different site, you will need to look into the setting of IIS to find it. It is common also to have IIS host the SVC as default page so you could have just the first two parts and not the actual page in your URI. I don't think you will have much luck unless you start digging into your web server.

Categories

Resources