मैं निम्नलिखित एपीआई के साथ एक RESTful WCF वेब सेवा है:WebGet कोई पैरामीटर या UriTemplate साथ विफल
[WebGet(ResponseFormat = WebMessageFormat.Json)]
MyResponseContract GetFileInfo();
जब अंत बिंदु (SOAPUI उपयोग करते हुए) मैं निम्न त्रुटि संदेश दिखाई हिट करने के लिए प्रयास कर रहा:
सर्वर को अनुरोध को संसाधित करने में त्रुटि आई। सेवा के वैध अनुरोधों के निर्माण के लिए कृपया सेवा सहायता पृष्ठ देखें।
मेरे पास SOAPUI इसे एक GET विधि कॉल के साथ हिट करने के लिए सेट है। जब मैं इसे किसी भी शरीर के साथ POST पर स्विच करता हूं, तो यह निम्न संदेश से विफल रहता है:
विधि की अनुमति नहीं है।
यह सही समझ में आता है: एक पोस्ट के साथ प्राप्त नहीं कर सकता। तो मैं अपने कोड के रूप में इस अद्यतन:
[WebInvoke(ResponseFormat = WebMessageFormat.Json)]
MyResponseContract GetFileInfo();
और अब मैं एक पोस्ट विधि के साथ SOAPUI से इसे कहते हैं और यह काम करता है। जिज्ञासु।
[WebInvoke(ResponseFormat = WebMessageFormat.Json, Method = "GET")]
MyResponseContract GetFileInfo();
मैं कुछ पदों में देखा है कि इस अनिवार्य रूप से एक WebGet
विशेषता के बराबर है: तो मैं अब इस प्रकार के रूप में मेरे कोड बदल जाते हैं। यह भी काम नहीं करता है।
तो मेरा सवाल यह है कि यह WebGet
के रूप में क्यों काम नहीं करता है, भले ही मैं पैरामीटर स्वीकार नहीं कर रहा हूं या कस्टम UriTemplate का उपयोग नहीं कर रहा हूं?
यूआरएल मैं (यह IIS में स्थानीय स्तर पर होस्ट किया गया है) के साथ यह हिट करने के लिए कोशिश कर रहा हूँ है:
http://localhost/Utilities/API/GetFileInfo
अद्यतन नीचे टिप्पणी और दिए गए उत्तर को देखते हुए, मैं अभी भी का सामना करना पड़ रहा यह समस्या। कुछ अतिरिक्त विवरण।
मेरे वेब-परत web.config
<?xml version="1.0"?>
<configuration>
<system.web>
<compilation debug="true" targetFramework="4.0" />
<customErrors mode="Off" />
</system.web>
<system.serviceModel>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
<standardEndpoints>
<webHttpEndpoint>
<standardEndpoint name="" helpEnabled="true" automaticFormatSelectionEnabled="true" maxReceivedMessageSize="10000000" />
</webHttpEndpoint>
</standardEndpoints>
<behaviors>
<endpointBehaviors>
<behavior name="exampleBehavior">
<callbackDebug includeExceptionDetailInFaults="true" />
<enableWebScript />
<webHttp helpEnabled="true" />
</behavior>
</endpointBehaviors>
</behaviors>
<bindings>
<webHttpBinding>
<binding name="WebHttpBinding" maxReceivedMessageSize="10000000" />
</webHttpBinding>
</bindings>
<client>
<endpoint address="http://LOCALHOST/Utilities.AppService/API"
binding="webHttpBinding" bindingConfiguration="WebHttpBinding"
contract="Utilities.Common.API.IMyApi"
behaviorConfiguration="exampleBehavior" />
</client>
</system.serviceModel>
</configuration>
मेरा ऐप परत web.config:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.web>
<compilation debug="true" targetFramework="4.0" />
<customErrors mode="Off" />
</system.web>
<system.serviceModel>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
<standardEndpoints>
<webHttpEndpoint>
<standardEndpoint name="" helpEnabled="true" automaticFormatSelectionEnabled="true" maxReceivedMessageSize="10000000" />
</webHttpEndpoint>
</standardEndpoints>
</system.serviceModel>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true" />
<handlers>
<remove name="ExtensionlessUrlHandler-Integrated-4.0" />
<add name="ExtensionlessUrlHandler-Integrated-4.0" path="*." verb="GET,HEAD,POST,DEBUG,PUT,DELETE" type="System.Web.Handlers.TransferRequestHandler" resourceType="Unspecified" requireAccess="Script" preCondition="integratedMode,runtimeVersionv4.0" />
</handlers>
</system.webServer>
</configuration>
मेरी सेवा इंटरफ़ेस
[ServiceContract(Namespace = "API")]
public interface IMyApi
{
[WebGet]
MyResponseContract GetFileInfo();
}
मेरे वेब-परत कार्यान्वयन
[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Required)]
[ServiceBehavior(InstanceContextMode = InstanceContextMode.Single, ConcurrencyMode = ConcurrencyMode.Multiple)]
public class MyApiWebService : ClientBase<IMyApi>, IMyApi
{
public MyResponseContract GetFileInfo()
{
return Channel.GetFileInfo();
}
}
मेरा ऐप परत कार्यान्वयन
[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Required)]
[ServiceBehavior(InstanceContextMode = InstanceContextMode.Single, ConcurrencyMode = ConcurrencyMode.Multiple)]
public class MyApiAppService : IMyApi
{
public MyResponseContract GetFileInfo()
{
return new MyResponseContract();
}
}
मेरे वेब-परत Global.asax:
protected void Application_Start(object sender, EventArgs e)
{
RouteTable.Routes.Add(new ServiceRoute("API", new WebServiceHostFactory(), typeof(MyApiWebService)));
}
मेरा ऐप परत वैश्विक।Asax:
protected void Application_Start(object sender, EventArgs e)
{
RouteTable.Routes.Add(new ServiceRoute("API", new WebServiceHostFactory(), typeof(MyApiAppService)));
}
मुझे यकीन नहीं है कि मैं कितना अधिक विवरण प्रदान कर सकता हूं। जैसा कि आप देख सकते हैं, दिए गए समाधान दिए गए हैं, मैंने सुझाए गए सब कुछ लागू किए हैं। चाहे मैं ब्राउजर में वेब लेयर सर्विस यूआरएल डालकर या एसओएपीयूआई का उपयोग करके इस सेवा को WebGet
विधि को हिट करने की कोशिश कर रहा हूं, या सेवा क्लाइंट का उपयोग कर सी # यूनिट टेस्ट के साथ इसे मारने की कोशिश कर रहा हूं, मैं WebGet
का उपयोग करने में असमर्थ हूं। आपसे मिली हर मदद के लिए धन्यवाद।
और दिलचस्प नोट यह है कि ऐप-लेयर यूआरएल काम करता है। लेकिन वेब परत नहीं है। तो:
localhost/Utilities.AppService/API/GetFileInfo
काम करता है, जबकि
localhost/Utilities.WebService/API/GetFileInfo
नहीं करता है।
तुम इसे कैसे एक्सेस कर रहे हैं:
क्या इस तरह दिखता है, यहां प्रदर्शित करने के लिए मेरी अद्यतन, काम कर वेब सेवा कार्यान्वयन की तरह लग रहा है? और स्पष्ट होने के लिए आखिरी व्यक्ति काम नहीं करता था? –
अनुरोधित विवरण के साथ अद्यतन प्रश्न। –
क्या आप 'WebHttp बाइंडिंग' का उपयोग कर रहे हैं? –