1

New-> projects-> WCF Service Applicationに移動してwcfrestサービスを作成しましたwcfrestサービスをホストし、アプリケーションでwcf restサービスを参照している間、コンソールアプリケーションでメソッドを使用できませんアプリケーションコードは次のとおりです:
IRestServiceImpL

    [ServiceContract]
        public interface IRestServiceImpL
        {
        [OperationContract]
        [WebInvoke(Method = "GET", ResponseFormat = WebMessageFormat.Xml, 
        RequestFormat = WebMessageFormat.Xml, UriTemplate = "XmlData/{id}")]
        string XmlData(string id);

        [OperationContract]
        [WebInvoke(Method = "GET", ResponseFormat = WebMessageFormat.Json, 
        RequestFormat = WebMessageFormat.Json, UriTemplate = "JsonData/{id}")]
        string JsonData(string id);
        }



RestServiceImpL.svc.cs

[AspNetCompatibilityRequirements(RequirementsMode
= AspNetCompatibilityRequirementsMode.Allowed)]
    public class RestServiceImpL : IRestServiceImpL
    {
       public string XmlData(string id)
       {
            return "you requested for " + id;
        }

        public string JsonData(string id)
        {
            return "you requested for " + id;
        }
}



構成ファイル

    <system.web>
        <compilation debug="true" targetFramework="4.0" />
    </system.web>
    <system.serviceModel>
    <bindings>
        <webHttpBinding>
            <binding name="StreamedRequestWebBinding"
                     bypassProxyOnLocal="true"
                     useDefaultWebProxy="false"
                     hostNameComparisonMode="WeakWildcard"
                     sendTimeout="10:15:00"
                     openTimeout="10:15:00"
                     receiveTimeout="10:15:00"
                     maxReceivedMessageSize="2147483647"
                     maxBufferSize="2147483647"
                     maxBufferPoolSize="2147483647"
                     transferMode="StreamedRequest"
                     crossDomainScriptAccessEnabled="true"
             >
                <readerQuotas maxArrayLength="2147483647"
                              maxStringContentLength="2147483647" />
            </binding>
        </webHttpBinding>
    </bindings>
    <services>
        <service name="RestService.RestServiceImpL" behaviorConfiguration="ServiceBehaviour">
            <!--<endpoint address="" binding="basicHttpBinding"  contract="RestService.IRestServiceImpL"></endpoint>-->
            <endpoint address="" binding="webHttpBinding" name="StreamedRequestWebBinding" bindingConfiguration="StreamedRequestWebBinding"  contract="RestService.IRestServiceImpL" behaviorConfiguration="web"></endpoint>
        </service>
    </services>

    <behaviors>
        <serviceBehaviors>
            <behavior name="ServiceBehaviour">
                <!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment -->
                <serviceMetadata httpGetEnabled="true"/>
                <!-- To receive exception details in faults for debugging purposes, set the value below to true.  Set to false before deployment to avoid disclosing exception information -->
                <serviceDebug includeExceptionDetailInFaults="false"/>
            </behavior>
        </serviceBehaviors>
        <endpointBehaviors>
            <behavior name="web">
                <webHttp/>
            </behavior>
        </endpointBehaviors>
    </behaviors>
    <serviceHostingEnvironment multipleSiteBindingsEnabled="true" aspNetCompatibilityEnabled="true" />
</system.serviceModel>
<system.webServer>
    <httpProtocol>
        <customHeaders>
            <add name="Access-Control-Allow-Origin" value="*"/>
        </customHeaders>
    </httpProtocol>
    <modules runAllManagedModulesForAllRequests="true"/>
</system.webServer>



このサービスアプリケーションをIISでホストしています

プロキシクラスを使用してメソッドを呼び出すときにコンソールアプリケーションを参照した後、エンドポイントが指定されていない

呼び出しコードが以下であるという無効な操作コントラクト例外のエラーが発生しました:

ServiceClient oServiceClient = new ServiceClient();<br/>
oServiceClient.JsonData("123");


コードの何が問題なのかを提案してください。

4

1 に答える 1

3

サポートのためのスタックオーバーフローに感謝します...私はそれをしました..呼び出しているWcfRestServiceコードは以下に書かれています:

//code for xml Response consumption from WCF rest Service[Start]
WebRequest req = WebRequest.Create(@"http://RestService.com/WcfRestService/RestServiceImpL.svc/XmlData/sad");
req.Method = "GET";
req.ContentType = @"application/xml; charset=utf-8";
HttpWebResponse resp = req.GetResponse() as HttpWebResponse;
if (resp.StatusCode == HttpStatusCode.OK)
{
    XmlDocument myXMLDocument = new XmlDocument();
    XmlReader myXMLReader = new XmlTextReader(resp.GetResponseStream());
    myXMLDocument.Load(myXMLReader);
    Console.WriteLine(myXMLDocument.InnerText);
}
//code for xml Response consumption from WCF rest Service[END]

//****************************************************************************
//code for json Response consumption from WCF rest Service[Start]
WebRequest req2 = WebRequest.Create(@"http://RestService.com/WcfRestService/RestServiceImpL.svc/JsonData/as");
req2.Method = "GET";
req2.ContentType = @"application/json; charset=utf-8";
HttpWebResponse response = (HttpWebResponse)req2.GetResponse();
string jsonResponse = string.Empty;
using (StreamReader sr = new StreamReader(response.GetResponseStream()))
{
    jsonResponse = sr.ReadToEnd();
    Console.WriteLine(jsonResponse);
}
//code for json Response consumption from WCF rest Service[END]
于 2012-12-28T16:15:48.737 に答える