I have a WCF SOAP service with the following method:
[OperationContract]
string GetDetails(string param1);
Method GetDetails returns JSON string. I tested the method and it works as expected. When I run the service with WCF Test Client and pass in a parameter, it spits out a string in JSON format. But if I call the service from browser:
http://ServerName/projectName/ServiceName.svc/GetDetails/12345
I get an error Resource not found.
Can anyone explain what am I doing wrong?
Navigating to a URL in a browser performs a GET request on that resource. SOAP methods all use POST.
If you would test this with a program like Fiddler or Postman, you can test the different kind of HTTP methods like GET or POST. If you would perform a GET on your URL in fiddler you would get the same result as in the browser. Performing a POST would give you the same result as with the WCF Test Client.
Related
I am new to web services.
I have built a web service in C# that consumes a third party service and then returns the XML response from that call in a web method.
When I test this in IIS on the local web server it works perfectly.
However when I try to call or invoke the service via the URL I use on the test page I can't return a response.
If I use a GET I simply get the test page loading and the message I can't use this test page outside of the local server.
In short, I simply want to know how to call the web method externally and mimic the INVOKE button being pressed so I get the response passed back.
This is probably really simple but I can't get my head around it.
In addition if I use Postman to try and call the URL:
WebService.asmx?op=GetSalesOrders
I get the error message detailed below which is a step forward but I am still unsure about how to package up a call to this service
You call the service by making a POST request with a properly formated SOAP message to this URL:
<path>/WebService.asmx
You get the WSDL of the web service by making a GET request to this URL:
<path>/WebService.asmx?wsdl
You can use that WSDL to build a client or test the service with something like SoapUI. See this and this for more details.
That invocation page or URLs with parameters like this:
<path>/WebService.asmx?op=GetSalesOrders
are just provided for convenience to allow you to poke at the service and make sure the service is running. They should not be used in "real" calls.
I need to call an external SOAP webservice over HTTP.
I have the WSDL file and added it in Visual Studio via 'Add service reference'. Visual studio then added a number of files, in the reference file i can find this:
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "4.0.0.0")]
[System.ServiceModel.ServiceContractAttribute(ConfigurationName="Service.IService")]
public interface IService {
[System.ServiceModel.OperationContractAttribute(Action="http://tempuri.org/IService/Function", ReplyAction="http://tempuri.org/IService/FunctionResponse")]
namespace.Service.ExecuteFunctionResponse ExecuteFunction(namespace.Service.FunctionRequest request);
}
With additionaly the async version of this call and the objects for sending an receiving, etc.
To call the service I added the folowing code:
BasicHttpBinding binding = new BasicHttpBinding();
EndpointAddress endpointAddress = new EndpointAddress("the address");
serviceChannel = new ServiceClient(binding, endpointAddress).ChannelFactory.CreateChannel();
Response response = serviceChannel.ExecuteFunction(new Request(...));
This results in me getting an exception, error 405 method not allowed.
So it appears I must use a HTTP GET request instead of the default POST request. But i cannot find where this can be altered in with this way of working.
So, where can i set the HTTP method for this call to a webservice?
SOAP services are using HTTP POST because they exchange XML messages (which tend to be complex) and cannot be transferred in a query string.
Are you sure that you must use HTTP GET? Maybe the error you are receiving "405 method not allowed" is caused by some bad configuration.
I would double check the SOAP endpoint URL is set correctly and check that there are no additional security requirements needed.
EDIT
In past, there was a practice to create ASP.NET Web Services which would accept GET as well. But they wouldn't expect XML messages. Instead, you would have to pass all parameters in a querystring. For example: https://foo.bar/service.asmx/Func?param1=X¶m2=Y (where param1 and param2 are the expected parameters).
This way it is possible to call a WebService without a need for WSDL and using GET method. You can achieve it by using HttpClient for example.
The downside of this approach is that you will have to deal with plain data instead of objects.
I hope it might help.
I am trying to call rest service which is creating with WebChannelFactory in soap service. I am using .net framework 4.0.
I have issue with request format.
Unit test and sample aspx page working as expected. But when calling rest service in soap method, request format setted as xml instead of json.
It is look like soap content-type request header used for new rest header.
We neeed new OperationContextScope for rest environment before request like below.
using (OperationContextScope scope = new OperationContextScope((IContextChannel)proxy))
{
proxy.myMethod();
}
http://example.com/ShaktiERPService/UpdateErpSrvc.svc?wsdl
i have one wcf service URL similar to above url... where i written one method (UpdateData) with 4 parameters. And this method is returning a string as response like "successfully updated" or "failed to update"
[ServiceContract]
public interface IUpdateErpSrvc
{
[OperationContract]
[WebGet(UriTemplate = "UpdateData/{Erp_Ord_No}/{SFDC_Order_No}/{usr}/{pass}")]
string UpdateData(string Erp_Ord_No, string SFDC_Order_No, string usr, string pass);
}
and My method is here:
public class UpdateErpSrvc : IUpdateErpSrvc
{
public string UpdateData(string Erp_Ord_No, string SFDC_Order_No, string usr, string pass)
{
ServiceRepository repo = new ServiceRepository();
return repo.UpdateData(Erp_Ord_No, SFDC_Order_No, usr, pass);
}
}
This service is working perfect in project...
But i want to check this in postman & fiddler....
I don't have any idea to check..
I tried so many time but didn't get response...
So please help me related to this problem..
Hope this helps you,
Fiddler is debugging tool.
Postman is best suitable to test your Web API methods. It can also be
used against 3rd party APIs and Open .
So, if your web service is with RESTful properties you can go with Postman to test the functionality of your web service.
However you can have fiddler in parallel to check the Request and Response in various formats such as
Normal Headers
without any extra effort.
Also, POSTMAN helps you to easily add the header fields , data, etc with Sophisticated User Interface when compared to Fiddler
Update 1:
As per your sample Code you are trying to using a GET request which works absolutely fine, how ever not a recommended standard.
Also, would like to know if your using Entity Framework for accessing the data, if so update your post with the necessary code to help you further.
You can use SOAPUI to test for WCF services. Check https://www.soapui.org/
to download. You can easily put your wsdl address and can just run your request.
Why don't you use WCFTestClient for checking your WCF service. It would clearly show you the request and response in XML format.
I am developing the REST enabled WCF Service. I am using the following code inside the interface.
[OperationContract]
//[WebGet]
[WebInvoke(Method = "GET",
ResponseFormat = WebMessageFormat.Json, RequestFormat = WebMessageFormat.Json)]
List<String> GetProjects();
I want the method should return the JSON response. I am passing the parameter through the URL as follows.
http://localhost:51565/RestWebService/Search.svc/GetProjects
Now when I use the above URL in the address bar, the browser ask me for downloading the file. I am new the REST web service & also JSON. I am not aware whether in the above case I am getting the JSON response or something else ? How can I identify that the above response is the JSON response ?
Most of the the current browsers do not render Json when they see the media-type application/json. You will run into this problem with many media types. My suggestion is to just stop trying to debug using a web browser.
Install fiddler. It will save you.
Fiddler is a debugging tool for working with HTTP. You will be able to see exactly what is being transmitted to and from your service and you will be able to create POST requests in order to test your service.
It does take a bit of time to get used to but it is well worth it if you are doing any amount of work with HTTP.
Download file and look inside if you have a valid json object. Eventually parse using jQuery.parseJSON.
Browser propmts you to download because it received a content type is does not understand, does not have too much to do with content. It is not the responsability of the browser to decide if its a valid json but of the calling code.
I second fiddler for its JSON support, but for instances where you can call the service with a GET request then Chrome will display the result in the browser just fine.
Just copied this out a Chrome tab after calling a WCF service
{"GetDetailResult":{"Address":null,"MainPhotoURL":null,"Photos":[]}}