ajax - Sharepoint 2010 wcf service. call method with jquery -
i have wcf service hosed in sharepoint application. when try call method jquery fails.
i have tested service such string:
ttp://localhost/_vti_bin/webservices/wcfservice.svc/**mex**
and have normal response.
wcf test client have response too.
but in javascript code recieve error. why? doing wrong?
$.ajax({ url: "/_vti_bin/webservices/wcfservice.svc/helloworld", datatype: 'json', contenttype: "application/json", success: function (res) { alert("good answer"); }, error: function (xhr) { alert("error"); return; } });
browser response:
<wsdl:definitions name="wcfservice" targetnamespace="http://tempuri.org/"> <wsp:policy wsu:id="basichttpbinding_wcfservice_policy"> <wsp:exactlyone> <wsp:all> <http:ntlmauthentication/> </wsp:all> </wsp:exactlyone> </wsp:policy> <wsp:policy wsu:id="basichttpbinding_wcfservice2_policy"> <wsp:exactlyone> <wsp:all> <http:ntlmauthentication/> </wsp:all> </wsp:exactlyone> </wsp:policy> <wsdl:types> <xsd:schema targetnamespace="http://tempuri.org/imports"> <xsd:import schemalocation="http://localcomputer/_vti_bin/.webservices/wcfservice.svc/mex xsd=xsd0" namespace="http://tempuri.org/"/> <xsd:import schemalocation="http://localcomputer/_vti_bin/.webservices/wcfservice.svc/mex xsd=xsd1" namespace="http://schemas.microsoft.com/2003/10/serialization/"/> </xsd:schema> </wsdl:types> <wsdl:message name="wcfservice_helloworld_inputmessage"> <wsdl:part name="parameters" element="tns:helloworld"/> </wsdl:message> <wsdl:message name="wcfservice_helloworld_outputmessage"> <wsdl:part name="parameters" element="tns:helloworldresponse"/> </wsdl:message> <wsdl:porttype name="wcfservice"> <wsdl:operation name="helloworld"> <wsdl:input wsaw:action="http://tempuri.org/wcfservice/helloworld" message="tns:wcfservice_helloworld_inputmessage"/> <wsdl:output wsaw:action="http://tempuri.org/wcfservice/helloworldresponse" message="tns:wcfservice_helloworld_outputmessage"/> </wsdl:operation> </wsdl:porttype> <wsdl:binding name="basichttpbinding_wcfservice" type="tns:wcfservice"> <wsp:policyreference uri="#basichttpbinding_wcfservice_policy"/> <soap:binding transport="http://schemas.xmlsoap.org/soap/http"/> <wsdl:operation name="helloworld"> <soap:operation soapaction="http://tempuri.org/wcfservice/helloworld" style="document"/> <wsdl:input> <soap:body use="literal"/> </wsdl:input> <wsdl:output> <soap:body use="literal"/> </wsdl:output> </wsdl:operation> </wsdl:binding> <wsdl:binding name="basichttpbinding_wcfservice1" type="tns:wcfservice"> <soap:binding transport="http://schemas.xmlsoap.org/soap/http"/> <wsdl:operation name="helloworld"> <soap:operation soapaction="http://tempuri.org/wcfservice/helloworld" style="document"/> <wsdl:input> <soap:body use="literal"/> </wsdl:input> <wsdl:output> <soap:body use="literal"/> </wsdl:output> </wsdl:operation> </wsdl:binding> <wsdl:binding name="basichttpbinding_wcfservice2" type="tns:wcfservice"> <wsp:policyreference uri="#basichttpbinding_wcfservice2_policy"/> <soap:binding transport="http://schemas.xmlsoap.org/soap/http"/> <wsdl:operation name="helloworld"> <soap:operation soapaction="http://tempuri.org/wcfservice/helloworld" style="document"/> <wsdl:input> <soap:body use="literal"/> </wsdl:input> <wsdl:output> <soap:body use="literal"/> </wsdl:output> </wsdl:operation> </wsdl:binding> <wsdl:service name="wcfservice"> <wsdl:port name="basichttpbinding_wcfservice" binding="tns:basichttpbinding_wcfservice"> <soap:address location="http://localcomputer/_vti_bin/.webservices/wcfservice.svc"/> </wsdl:port> </wsdl:service> </wsdl:definitions>
code of service:
[basichttpbindingservicemetadataexchangeendpoint] [aspnetcompatibilityrequirements(requirementsmode = aspnetcompatibilityrequirementsmode.required)] [servicecontract] public class wcfservice { // test service, use visual studio wcf test client // set endpoint http://<your server name>/_vti_bin/webservices/wcfservice.svc/mex [operationcontract] //[webget(uritemplate = "helloworld", responseformat = webmessageformat.json, bodystyle = webmessagebodystyle.bare)] [webinvoke(requestformat = webmessageformat.json, uritemplate="/helloworldm", bodystyle = webmessagebodystyle.wrapped)] public string helloworld() { return "hello world wcf , sharepoint 2010"; } }
try use multiplebaseaddresswebservicehostfactory instead of multiplebaseaddressbasichttpbindingservicehostfactory in svc files.
Comments
Post a Comment