how to consume .svc file - asp.net

I have got url for svc file. For example https://Myservicelocation/UserService.svc.
Now i tried to create asp.net web application in visual studio and added this url using "Add service reference". When i put this url and then click go i get error
The request failed with HTTP status 400: Bad Request.
Metadata contains a reference that cannot be resolved: 'https://Myservicelocation/UserService.svc'.
Content Type application/soap+xml; charset=utf-8 was not supported by service https://Myservicelocation/UserService.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.
How can i resolve this?

Google says..
Probably a mismatch in the client/server bindings, where the message version in the service uses SOAP 1.1 (which expects application/soap+xml) and the version in the client uses SOAP 1.2 (which sends text/xml). WSHttpBinding uses SOAP 1.2, BasicHttpBinding uses SOAP 1.1.
Align your bindings accordingly...

I had the same problem.
Try https://Myservicelocation/UserService.svc?wsdl link.

Related

XI52 IBM Websphere DataPower

I have a service like this
MPGW <===> WSP <===> Backend
On the response, I have an attachment which I was expecting the type to be 'XOP' but instead I'm getting 'MIME' . Is there any way I can over ride to XOP?
FYI...when I hit the service directly the back-end (by passing datapower), I'm getting XOP attachment type.
Processing MTOM with SOAP 1.1 is not supported in DataPower so make sure you are using SOAP 1.2.
You need to check if it is the WSP (likely) or the MPGW that is changing the response. This you can do using the Probe.
You can handle the attachments in a MTOM Policy for the service. Also use pass-through if possible for the MPGW to make sure it is not changing the payload.

Can't get authentication token from web api 2

I am new to Web Api 2. I am trying to build a project to explore token authorization. I created a new project in VS 2013 and selected the WebApi2 template and used Fiddler to emulate http requests. I didn't change anything in the template, just ran it as it was and tried to play with it with Fiddler. I successfully created a user by issuing request to /api/account/register but I can't login by issuing a POST request to the /Token endpoint. The request is:
http://localhost:YYYY/token?grant_type=password&password=admin123456&username=admin
(i also tried to pass the parameters as a json object in the request body).
I get back this:
{"error":"unsupported_grant_type"}
From other posts such as ASP.NET WEB API 2 OWIN Authentication unsuported grant_Type I learned that I needed to enable CORS for web api and at the token endpoint, but that hasn't worked for me.
Are you sure that you are sending POST request message and not GET?
If you simply go to the URL with query string (or open connection to this URL from your code) you are sending GET message by default. It's not what WebAPI with "/token" path is listening for.
If you are calling web service from same place, CORS is not needed. The error "unsupported_grant_type" could be in the format of the data you are passing server in post action.
Try sending with Content-Type application/x-www-form-urlencoded

Return status code 4xx for client requests with invalid/unsupported Content-Type (like text/plain)

I've implemented a RESTful API using ASP.NET Web API (included in ASP.NET MVC 4).
When a client requests my services with an unsupported Content-Type (like "text/plain"), I get the following exception:
System.InvalidOperationException: No MediaTypeFormatter is available
to read an object of type [...] from content with media type
'text/plain'.
and my service returns a HTTP status code 500 and an error is logged/reported (I'm using ELMAH).
Unfortunately, I do not find an easy way to "catch" this type of unsupported client request. IMHO, the service should return a status code like 404 (not found) or 400 (bad request), because the error is not a server error (but a client side error).
In another SO question I found this answer How do I configure the status code returned by my ASP.NET Web API service when the request has an unsupported Content-Type? which shows a possible solution by implementing a custom DelegatingHandler.
So my question is: Do I miss something? Is there any ASP.NET Web API built-in functionality that targets this problem...
I finally "fixed" the problem with a custom DelegatingHandler similar to this implementation
How do I configure the status code returned by my ASP.NET Web API service when the request has an unsupported Content-Type?.
You can find my implementation here: http://blog.janjonas.net/2012-09-05/asp_net-mvc_4_rc-web-api-return-http-status-code-4xx-invalidoperationexception-no-mediatypeformatter-available-read-object-type-content-media-type
You can certainly use your own custom DelegatingHandler or you can make your custom HttpModule
which will implement the IHttpModule and check the current http request and validate the request.

HOWTO override Axis2 request headers for .NET web service?

I have to use a 3rd party web service implemented in .NET 2.0 (on IIS, of course).
I have to make a java client. I am using wsdl2java to generate the SOAP stub.
As the original Apache Axis project now appears unmaintained, and I was having some problems parsing some responses from the service, I converted the client to use the latest (1.5) version of Axis2. Now, the .NET service won't even recognize my requests.
I managed to get the "chunking" turned off (where "stub" is a variable of type MumbleStub generated by wsdl2java, and I am showing what are several lines of code as one horrific line here):
stub._getServiceClient().getOptions().setProperty( HTTPConstants.CHUNKED, Boolean.FALSE);
.. so at least the service recognizes my request AS a request, albeit a bad one: "HTTP/1.1 400 Bad Request" is the response now (as opposed to an "intro / summary" page offering me a link to the WSDL).
I noticed that the Axis ("1") request had a different Content-TYpe header (text/xml, vs application/soap-xml), and I am wondering how to change this request header, if that is in fact the problem.
Alternately, has anybody else had this problem? Is the problem really the (undisplayable here, as it looks like "element injection" to the blog engine) ... xml version-"1.0" ... "XML meta intro tag" that Axis2 added to the beginning of the request?
WS-Deathstar, indeed.
As you mention the different content-type header I guess your client tries to send SOAP 1.2 requests and the 3rd party app only understands SOAP 1.1
Try changing the used soap version as AFAIK AXIS2 uses SOAP 1.2 by default
stub._getServiceClient().getOptions().setSoapVersionURI(org.apache.axiom.soap.SOAP11Constants.SOAP_ENVELOPE_NAMESPACE_URI);

HTTP Content-Type in ASP.Net SoapHttpClientProtocol

I have a problem with a Web Service Consumer written in ASP.NET. The error message is:
System.InvalidOperationException: Client found response content type of 'application/xml; charset=utf-8', but expected 'text/xml'.
The client is based on System.Web.Services.Protocols.SoapHttpClientProtocol. We can't change the Content-Type given by the provider, this has to be 'application/xml; charset=utf-8'. Is there any way to change what Content-Type the SoapHttpClientProtocol expects? Unfortunately, we are probably limited to .NET 1.1.
Thanks!
Update: We found a way to change the Content-Type sent by the provider, and this solved the problem. I'd still be curious to know how to change the expectations of the consumer though.
Add a
Service Reference
for such Web Service not the
Web Reference
in your .net client Application

Resources