web service calling
I'm novice at webservices. So, I have web service:
public interface IReportingService
{
[OperationContract]
void SendStatistics(StatisticsInfo info);
[OperationContract]
void CloseTranslationSession(StatisticsInfo info);
}
if I go to http://localhost/ReportingService.svc?wsdl, then I can s开发者_JAVA百科ee there some xml. Looks like it works. Now i want to invoke one of this methods from js. How can I do this?
It seems that you are trying to invoke a SOAP service from JavaScript. The answer in this StackOverflow question might help.
Additional info:
Just by doing a quick search on google on the following string "invoke soap from JS" it seems that there are quite a few libraries for doing that, besides the one in the link mentioned above.
While I have quite a lot of experience with web services, I am not able to make a recommendation on a particular library since I have never invoked SOAP from JavaScript.
SOAP services are primarily used by business applications. The message size is quite big and the protocol itself is quite complicated in places. In the world of the web REST web services are used instead.
If you are the owner of the service and JS is the main place from where it is going to be consumed, you should consider exposing it as REST rather than SOAP and return the data as JSON which is really easy to consume in JS.
Here you can find a short tutorial on setting up WCF REST services.
You can use Ajax (I suggest with JQuery).
$.ajax({
type: "POST",
contentType: "application/json; charset=utf-8",
url: "ReportingService.svc/SendStatistics",
data: "{YouDataHere}",
dataType: "json"
});
精彩评论