Making WCF Northwind Sharp Architecture works - wcf

Once again, as a beginner with WCF, MVC and Sharp Architecture, i might asking a stupid question, so bear with me.
I'm finally able to make the Northwind example of Sharp Architecture work.
I can browse the service using internet browser
localhost/NorthwindWcfServices/TerritoriesService.svc
localhost/NorthwindWcfServices/TerritoriesService.svc?wsdl
I can invoke the service GetTerritories using WcfTestClient.exe
And then i use Fiddler to test it :
Fiddler is ok when i Request a GET :
localhost/NorthwindWcfServices/TerritoriesService.svc?wsdl
when i start requesting
localhost/NorthwindWcfServices/TerritoriesService.svc/GetTerritories
They keep giving me a 400 Bad Request error.
Is there something i should do to make it work ?
Should i add a content-type in fiddler header request ? or should i add any attribute in the service class ?
Any help will be much appreciated.
Thanks

You have to configure the Service using the Web config file for example if u configure the WCF for accessing ... your service config should look something like this
<system.serviceModel>
<behaviors>
<serviceBehaviors>
<behavior name="ServiceBehavior">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="true" />
</behavior>
</serviceBehaviors>
<endpointBehaviors>
<behavior name="EndPBehavior">
<webHttp/>
<enableWebScript/>
</behavior>
</endpointBehaviors>
</behaviors>
<services>
<service behaviorConfiguration="ServiceBehavior" name="CastleTest.WCF.WCFService">
<endpoint address="" binding="webHttpBinding"
contract="CastleTest.WCF.IWCFService"
behaviorConfiguration="EndPBehavior"/>
</service>
</services>
try it and see if the error 400 goes or not

Related

Support about Webservice when hosting in IIS [duplicate]

This question already exists:
support about Web service when hosting in IIS
Closed 9 years ago.
I writing a Web service, when I run it in localhost, everything is OK, but I host in IIS 7.0 , it's not running. Please support me!!!
Here my Web.config
<system.serviceModel>
<services>
<service name="VivuFace_V2.api.CloudCameraService" behaviorConfiguration="VivuFace_V2.api.CloudCameraServiceBehavior">
<endpoint address="../CloudCameraService.svc"
binding="webHttpBinding"
contract="VivuFace_V2.api.ICloudCameraService"
behaviorConfiguration="webBehaviour" />
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="VivuFace_V2.api.CloudCameraServiceBehavior">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="false" />
</behavior>
</serviceBehaviors>
<endpointBehaviors>
<behavior name="webBehaviour">
<webHttp/>
</behavior>
</endpointBehaviors>
</behaviors>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
</system.serviceModel>
This is very open ended since there is no error message here, but my experience is that a lot of the time issues related to hosting under IIS is due to the following:
Make sure your app pool is configured for the right version of Net
Make sure asp.net support is installed in IIS
Make sure permissions are configured correctly

Endpoint not found when accessing via URL in a browser

When I enter the address of my service, I get to see the WSDL file. However, When I add a suffix to the URL, I get the error message: "endpoint not found". It's definitely due to something wrong with my service model declaration but after a few hours, I'm inclined to admit that it's beyond me.
I've made sure that the namespaces are correct as discussed here.
The first URL works. The other, don't.
http://---.azurewebsites.net/MyService.svc/
http://---.azurewebsites.net/MyService.svc/Ping
http://---.azurewebsites.net/MyService.svc/Ping/ (as suggested here)
In behaviors I've declared two behaviors - one for the end point and one for the service.
<behaviors>
<endpointBehaviors>
<behavior name="PingEndPointBehavior">
<webHttp/>
</behavior>
</endpointBehaviors>
<serviceBehaviors>
<behavior name ="PingServiceBehavior">
<serviceMetadata httpGetEnabled="true"
httpsGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="true"/>
</behavior>
<behavior name="">
<serviceMetadata httpGetEnabled="true"
httpsGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="false"/>
</behavior>
</serviceBehaviors>
</behaviors>
I declared the following binding for access via URL line in the browser.
<bindings>
<webHttpBinding></webHttpBinding>
</bindings>
In services I declared two end points (I tested with only the first one, as well).
<service name="MyProject.MyService"
behaviorConfiguration="PingServiceBehavior">
<endpoint name="PingEndPoint"
behaviorConfiguration="PingEndPointBehavior"
address="Ping"
binding="webHttpBinding"
contract="MyProject.IMyService"/>
<endpoint contract="IMetadataExchange"
binding="mexHttpBinding"
address="mex" />
</service>
I also have the following in my config file. Doubtful of its significance, but one never knows.
<serviceHostingEnvironment aspNetCompatibilityEnabled="true"
multipleSiteBindingsEnabled="true"/>
I've resolved the issue. Apparently, the virtual path of sub-directories is cumulative, so the exposed service was there all along but at the following address.
http://---.azurewebsites.net/MyService.svc/Ping/Ping
One ping level comes from the config file while the other from the template URI in the attribute that decorates the interface for the method.

Hosting WCF service on IIS (The resource cannot be found)

I am making WFC service. When I debug it from Visual Studio all is ok, but I've faced with problem when I deploy it on real IIS.
After deploying I still can get WSDL but when I request WebGet method (which returns a simple XML document) method I got the following error:
The resource cannot be found.
Description: HTTP 404. The resource you are looking for (or one of its dependencies) could have been removed, had its name changed, or is temporarily unavailable. Please review the following URL and make sure that it is spelled correctly.
What can be cause of problem?
My Web.Config:
<system.serviceModel>
<services>
<service name="XXXX.TSDX.UI.TsdxService">
<endpoint
address="Tsdx"
binding="webHttpBinding"
bindingConfiguration="TestBinding"
behaviorConfiguration="RESTFriendly"
contract="XXXX.TSDX.UI.ITsdxService" />
</service>
</services>
<bindings>
<webHttpBinding>
<binding name="TestBinding" />
</webHttpBinding>
</bindings>
<behaviors>
<serviceBehaviors>
<behavior name="">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="false" />
</behavior>
</serviceBehaviors>
<endpointBehaviors>
<behavior name="RESTFriendly">
<webHttp />
</behavior>
</endpointBehaviors>
</behaviors>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
</system.serviceModel>
Verify that the correct version of the .NET framework selected in the ASP.NET tab (in IIS) for your application
If you are hosting this service in MVC app please make sure to add below line to ignore controller routing conflict, I had this issue after struggling for sometime I found this answer which has resolved the issue.
routes.IgnoreRoute("{allsvc}", new { allsvc = #"..svc(/.*)?" });

WCF Configuration File for Browser Interaction?

I have a simple WCF 4.0 service with some simple methods and a property with a getter that returns List. The service works fine when connected to programatically. The getter is decorated as are the other methods on the Interface that define the service contract.
My next move is to make the service accessible via the IE web browser so server/deployment admins can do a "smoketest" after service installation.
This works currently:
http://localhost/myservice.svc?wsdl
But I need to take things further and get this to work:
http://localhost/myservice.svc/SmokeTest
and have results show in the browser, SmokeTest is the property with a getter that does stuff and returns the List I want to show in the browser.
So far I can't figure out what my config should look like. All help appreciated.
This is all I have in the web.config for the service. The endpoint is myservice.svc:
<behaviors>
<serviceBehaviors>
<behavior >
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="true"/>
</behavior>
</serviceBehaviors>
</behaviors>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
<services>
<service name="myservice.worker" >
<endpoint address="" binding="basicHttpBinding" contract="myservice.IServicio" />
</service>
</services>
related question, an explanation of what can and can't be done:
Invoking WCF services through a browser

Json web service max content length?

I have been building a Asp.net WCF web service with json format. Now I wanted to really test how its working when sending lots of data. The Content-Length of my http post is 65595. Directly when trying to connect I got error "HTTP/1.1 400 Bad Request" back. It seems like it's not even trying.
I know I'm sending valid json and what I'm sending is an array with about 1000 items, and the json for each item looks like this:
{"oid":0,"am":1,"me":2,"ofooid":0,"fooid":1104,"sync":1,"type":1,"id":1443,"date":"2009-09-24"}
If I just delete one of the items in the array so the total content-length is 65484 it works perfect. So it seems like it's a magic limit around there somewhere. Is it Asp.net that limit the size of the request, and how can I change the max size if that's the case?
My Web.Config file looks like, and I think I should set the maximum value here somewhere but I just don't know where:
<system.serviceModel>
<behaviors>
<endpointBehaviors>
<behavior name="ServiceAspNetAjaxBehavior">
<enableWebScript />
</behavior>
</endpointBehaviors>
<serviceBehaviors>
<behavior name="ServiceBehavior">
<serviceDebug includeExceptionDetailInFaults="true" />
</behavior>
</serviceBehaviors>
</behaviors>
<services>
<service behaviorConfiguration="ServiceBehavior" name="Service">
<endpoint address="" behaviorConfiguration="ServiceAspNetAjaxBehavior" binding="webHttpBinding" contract="Service" />
</service>
</services>
</system.serviceModel>
You need to increase the maxReceivedMessageSize in the binding configuration for WebHttpBinding. The default is 65536. See the WebHttpBinding configuration documentation for all of the information.
Also note that you may need to increase the ASP.NET maxRequestLength via the httpRuntime configuration. The default is 4 MB but you may need to increase:
<httpRuntime maxRequestLength="10000" />
As far as increasing the size of the request is concerned above mentioned answer is right but if you want to increase the size of the json response then you can do this by doing changes in the endpointBehaviors as mentioned below.
Also not that response may vary according to the nesting of the data, as we may return list with nested properties.
Assuming endpoint like this:
<endpoint address="" binding="webHttpBinding" contract="WcfService1.IService1" behaviorConfiguration="ClientBehavior">
For Client
<endpointBehaviors>
<behavior name="ClientBehavior">
<dataContractSerializer maxItemsInObjectGraph="10000000"/>
</behavior>
</endpointBehaviors>
For Server
<serviceBehaviors>
<behavior name="HostBehavior">
<dataContractSerializer maxItemsInObjectGraph="10000000"/>
</behavior>
<serviceBehaviors>