c#控制台应用程序中的wcf rest服务消耗

c#控制台应用程序中的wcf rest服务消耗,wcf,wcf-rest,Wcf,Wcf Rest,我通过“新建->项目->wcf服务应用程序”创建了wcf rest服务 我无法在控制台应用程序中使用方法,因为我在应用程序中托管了wcf rest服务并引用了wcf rest服务 我的申请代码如下: IRestServiceImpL <system.web> <compilation debug="true" targetFramework="4.0" /> </system.web> <system.servic

我通过“新建->项目->wcf服务应用程序”创建了wcf rest服务 我无法在控制台应用程序中使用方法,因为我在应用程序中托管了wcf rest服务并引用了wcf rest服务 我的申请代码如下:
IRestServiceImpL

    <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>


    <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>
ServiceClient oServiceClient = new ServiceClient();<br/>
oServiceClient.JsonData("123");
RestServiceImpL.svc.cs

    <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>


    <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>
ServiceClient oServiceClient = new ServiceClient();<br/>
oServiceClient.JsonData("123");
配置文件

    <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中托管此服务应用程序

    <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>
ServiceClient oServiceClient = new ServiceClient();<br/>
oServiceClient.JsonData("123");
现在,在我调用控制台应用程序的方法时引用了它 通过使用代理类,我得到了无效操作契约异常的错误 未指定该端点

呼叫代码如下:

    <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>
ServiceClient oServiceClient = new ServiceClient();<br/>
oServiceClient.JsonData("123");
ServiceClient-oServiceClient=newserviceclient()
oServiceClient.JsonData(“123”);

    <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>

请建议代码中的问题。

感谢堆栈溢出的支持…我做到了。。
    <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>
调用Wcf Rest服务代码如下所示:

    <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>
//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]

请建议我如何从应用程序使用wcf rest服务。上述调用代码的方法是错误的还是我使用了其他代码?请建议。。。。谢谢