Using WCF Service on web host server - asp.net

The possibility of this being a duplicate question is high.
The reason I'm querying it again, is that I have searched through tons of articles to no avail. I need some guidance, perhaps it may be specific to my application.
I've written a WCF Service, which works fine on the localhost.
Once the website is published to the live hosting server,
* I cannot access the WSDL - I obtain a 404 - File or directory not found.
* Should I try an add a service reference to the application, I get:
There was an error downloading 'http://freewaytoyota.co.za/FreewayToyotaService.svc/$metadata'.
The request failed with HTTP status 403: ModSecurity Action.
Metadata contains a reference that cannot be resolved: 'http://freewaytoyota.co.za/FreewayToyotaService.svc'.
The HTTP request was forbidden with client authentication scheme 'Anonymous'.
The remote server returned an error: (403) Forbidden.
If the service is defined in the current solution, try building the solution and adding the service reference again.
My web.config is as follows:
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="BasicHttpBinding_IFreewayToyotaService" />
</basicHttpBinding>
</bindings>
<client>
<endpoint address="http://localhost:8777/FreewayToyotaService.svc"
binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IFreewayToyotaService"
contract="FreewayServiceReference.IFreewayToyotaService" name="BasicHttpBinding_IFreewayToyotaService" />
</client>
<behaviors>
<serviceBehaviors>
<behavior name="">
<serviceMetadata httpGetEnabled="true" httpsGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="true"/>
</behavior>
</serviceBehaviors>
</behaviors>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" minFreeMemoryPercentageToActivateService="1"/>
</system.serviceModel>
I have not made any changes. This is the original file.
How do I modify it to get the .svc working on the live web host server.
Please help :(. Thanks in advance.

Related

Problems with WCF Webservice and SSL

I've read lots of threads the last hours but I did not find a solution which is working for me :-(
So as already multiple other users I have problems calling a SVC-Webservice via SSL from my Windows Phone 7 application. On localhost it works fine. I've deployed the Webservice within my Webapplication. The service "MyService.svc" is in the root of the webapplication. On IIS I've only added HTTPS (from Startcom, using default Port 443) for this IP and made SSL required. I could open my web application and I could open the Webservice using any browser at http://mydomain.com/MyService.svc, from both server and local development machine. The page says I could call svcutil.exe https://mydomain.com/MyService.svc?wsdl. When I click on the link the data is display correct.
Now when I try to access it via WP7 app I always get the following error:
"There was no endpoint listening at https://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."
And inner details say: "The remote server returned an error: NotFound."
Here is the important part of my web.config. I don't know whether this is all required, as said I've copied it from multiple threads but at least in IE it works fine:
<system.serviceModel>
<behaviors>
<serviceBehaviors>
<behavior name="MyBehavior">
<serviceMetadata httpsGetEnabled="true" httpGetEnabled="false" />
<serviceDebug includeExceptionDetailInFaults="true" />
<dataContractSerializer maxItemsInObjectGraph="1073741824" />
<useRequestHeadersForMetadataAddress>
<defaultPorts>
<add scheme="https" port="443" />
</defaultPorts>
</useRequestHeadersForMetadataAddress>
</behavior>
</serviceBehaviors>
</behaviors>
<services>
<service behaviorConfiguration="MyBehavior" name="MyNamespace.MyService">
<endpoint address="" binding="wsHttpBinding" bindingConfiguration="HttpsBinding"
contract="MyNamespace.IMyService">
</endpoint>
<endpoint address="mex" binding="mexHttpsBinding" contract="IMetadataExchange"/>
</service>
</services>
<bindings>
<wsHttpBinding>
<binding name="HttpsBinding">
<readerQuotas maxStringContentLength="2147483647" />
<security mode="Transport">
<transport clientCredentialType="None"/>
</security>
</binding>
</wsHttpBinding>
</bindings>
<!-- <serviceHostingEnvironment multipleSiteBindingsEnabled="true" /> -->
Many thanks!

WCF Not binding to urls

I have a small I have just written which uses the following uri template.
[UriTemplate = "xml/{user_id}/{content_id}/{time}")]
On my local dev machine
/blahblah.svc/xml/1/1/1
On my remote machine
/myapp/blahblah.svc/xml/1/1/1
Works, however when I try to deply this to a remote machine I get a 500 error, when I look at the 500 error the server appears to be trying to look for a web.config in blahblah.svc/xml/.
It does not appear to be binding to the url correctly after the blahblah.svc.
In my web.config I have :-
<system.serviceModel>
<services>
<service name="JASWebservices.JCPSRest" behaviorConfiguration="ServiceBehaviour">
<endpoint address ="" binding="webHttpBinding" contract="JASWebservices.IJCPSRest" behaviorConfiguration="web">
</endpoint>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="ServiceBehaviour">
<serviceMetadata httpGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="false"/>
</behavior>
</serviceBehaviors>
<endpointBehaviors>
<behavior name="web">
<webHttp/>
</behavior>
</endpointBehaviors>
</behaviors>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
</system.serviceModel>
So if I access this locally (on my dev machine) it works.
If I access this remotely on the prod server it 500s. The only difference I can see at present is the inclusion of the /myapp/ at the beginning since the prod server has multiple sites on it each to their own web app.
This was a strange one, so I've found a rather lacking problem in Microsoft WCF when using it for REST implementations using the UriTemplate + ServiceContract.
If you are using IIS and host this on a UNC path (ie a NFC or SMB or CIFS system) it does not work properly. You have to move the service to a local directory in order for it to run.
I tried this on two different boxes (one SMB and one NFS) using both Windows 7 and Windows Server 2008 R2 and the same issue appears on both.
Try to add this line
<endpoint name="mexHttpBinding" address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
after
<endpoint address ="" binding="webHttpBinding" contract="JASWebservices.IJCPSRest" behaviorConfiguration="web">
</endpoint>

ProtocolException Received when Calling WCF service

I am having this problem since a week now and am unable to resolve this. I have looked at various posts but found nothing related to the problem.
I have a website and a WCF service inside the same website project. It was all working fine, but suddenly, the WCF service client is not able to receive a valid response from the service.
Error message:
ProtocolException occured
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).
If using a custom encoder, be sure that the IsContentTypeSupported
method is implemented properly. The first 1024 bytes of the response
were: '
Value cannot be null.Parameter name: input
body {font-family:"Verdana";font-weight:norma....
I don't understand what is this parameter input. How can I resolve this issue? The WCF service is accessible via browser using the endpoint mentioned in the web.config
Here is the code:
Code behind:
using (var client = new Agent4HomeWebsite.PhotosWebServiceRef.PhotosWebServiceClient())
{
var temp = client.GetImageObjects();
}
Web.config:
<configuration>
....
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="BasicHttpBinding_IPhotosWebService" />
</basicHttpBinding>
</bindings>
<client>
<endpoint
address="http://localhost:49274/PhotosWebService.svc"
binding="basicHttpBinding"
bindingConfiguration="BasicHttpBinding_IPhotosWebService"
contract="PhotosWebServiceRef.IPhotosWebService"
name="BasicHttpBinding_IPhotosWebService" />
</client>
<behaviors>
<serviceBehaviors>
<behavior name="">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="false" />
</behavior>
</serviceBehaviors>
</behaviors>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
</system.serviceModel>
</configuration>

IIS Hosted WCF Service won't accept https endpoint, receive 404 resource error

Despite all of my efforts, I have not been able to get my simple WCF service hosted on IIS with SSL.
We are using windows server 2k3 with IIS 6.0 and we have up to .NET 4.0 installed on the server (web site is configured for 4.0)
If i go to http//.../rptService.svc url, I get the .svc page with the code blocks and ?wsdl url
on the other hand, if i go to https//.../rptService.svc I get a "Resource not found" 404 error. (colons on urls are removed b/c of spam prevention)
The web site has a working SSL certificate enabled for it.
My relevant web.config file is as follows:
<system.serviceModel>
<bindings>
<wsHttpBinding>
<binding name="rptBinding">
<security mode="Transport">
<transport clientCredentialType="None"/>
</security>
</binding>
</wsHttpBinding>
</bindings>
<behaviors>
<serviceBehaviors>
<behavior name="wcfApp.rptServiceBehavior">
<serviceDebug includeExceptionDetailInFaults="true"/>
<serviceMetadata httpsGetEnabled="false" httpGetEnabled="true" />
<serviceTimeouts/>
</behavior>
</serviceBehaviors>
</behaviors>
<services>
<service behaviorConfiguration="wcfApp.rptServiceBehavior"
name="wcfApp.rptService">
<endpoint binding="wsHttpBinding" bindingConfiguration="rptBinding" contract="wcfApp.rptService"
address="">
</endpoint>
<endpoint name="MetadataBinding" address="mex" binding="mexHttpsBinding" contract="IMetadataExchange" />
</service>
</services>
I have tried just about 100 different ways to write the web.config file from 150 different blog/web posts with similar situations, and have not gotten anything to work thus far.
My end goal is to get this wcf service hosted accepting a username/password token with a custom user name validator, but right now I can't even get it working with SSL!
Application is being built in VS 2010.
Please let me know if there is any more information that I can provide.
Any help is appreciated!

Silverlight authentication and ICredential

I've setup up a WCF web service to handle requests from a Silverlight application. That service has Windows authentication set up which works well with the following endpoint configuration
<system.serviceModel>
<behaviors>
<serviceBehaviors>
<behavior name="Test.Service.ServiceBehavior">
<serviceMetadata httpGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="true"/>
</behavior>
</serviceBehaviors>
</behaviors>
<bindings>
<customBinding>
<binding name="customBinding0">
<binaryMessageEncoding/>
<httpTransport authenticationScheme="Negotiate"/>
</binding>
</customBinding>
</bindings>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true"/>
<services>
<service behaviorConfiguration="Test.Service.ServiceBehavior" name="Test.Service.Service">
<endpoint address="" binding="customBinding" bindingConfiguration="customBinding0" contract="Test.Service.Service"/>
<endpoint address="mex" binding="customBinding" bindingConfiguration="customBinding0" contract="IMetadataExchange"/>
</service>
</services>
</system.serviceModel>
The service also has the following code in the constructor which authenticates to a TFS server
teamFoundationServer = TeamFoundationServerFactory.GetServer(tfsServer);
teamFoundationServer.EnsureAuthenticated();
workItemStore = (WorkItemStore)teamFoundationServer.GetService(typeof(WorkItemStore));
Then I have a Silverlight application that uses this web service and contains the following code to access it
proxy = new ServiceClient("Service");
Lastly there is a host web site that only contains the .xap silverlight file. That site has also Windows authentication configured.
Both the service and the host are running in IIS.
The problem I'm having is that when the service authenticates with TFS I always get an exception
Microsoft.TeamFoundation.TeamFoundationServerUnauthorizedException: TF30063: You are not authorized to access
Since the service and the host are windows authenticated then the Silverlight application is most likely causing me problems. After googling Silverlight and authentication it seems like there is some issue realated for Silverlight to forwarding the credential from the host to the service. Has someone been able to accomplish this task ?
To provide further info then I've been able to get the current users username by doing
OperationContext.Current.ServiceSecurityContext.PrimaryIdentity.AuthenticationType
But that returns a WindowsIdentity which is not compatible with ICredential which the TFS API requires :(

Resources