4

ブラウザからURLをヒットしようとすると、WCFが新しく作成され、400の不正な要求エラーが発生します。

私のサービス契約は次のようになります

[OperationContract]
[WebInvoke(Method = "GET", UriTemplate = "GetUsers")]
string GetUsers();

私はすでにwebconfigに次のようにエントリを作成しました

<serviceMetadata httpGetEnabled="true"/>

ブラウザでヒットしたURLは

http://localhost:51561/AceWebService.svc/GetUsers

これがwebconfigの一部です:

<system.serviceModel>
    <services>
        <service name="AceWebService.AceWebService" behaviorConfiguration="AceWebService.AceWebServiceBehavior">
            <!-- Service Endpoints -->
            <endpoint address="" binding="wsHttpBinding" contract="AceWebService.IAceWebService">
                <!-- 
          Upon deployment, the following identity element should be removed or replaced to reflect the 
          identity under which the deployed service runs.  If removed, WCF will infer an appropriate identity 
          automatically.
      -->
                <identity>
                    <dns value="localhost"/>
                </identity>
            </endpoint>
            <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
        </service>
    </services>
    <behaviors>
        <serviceBehaviors>
            <behavior name="AceWebService.AceWebServiceBehavior">
                <!-- 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="true"/>
            </behavior>
        </serviceBehaviors>
    </behaviors>
</system.serviceModel>

ここでstackoverflowで利用可能なすべてのキューを参照しました..ヘルプが表示されません..変更を提案してください。

thnx

4

2 に答える 2

3

エンドポイントで定義された wsHttpBinding を使用しました。それを webHttpBinding に変更するだけで、機能するはずです。

于 2012-03-15T13:40:44.073 に答える
0

まず、GET リクエストに WebGet を使用します。次に、サービス コントラクト インターフェイスを使用せずにサービスを動作させ、動作しているときにコントラクトをインターフェイスに移動します。

これは私のために働く:

[ServiceBehavior(InstanceContextMode = InstanceContextMode.PerCall)]
[ServiceContract]
public class HelloService 
{

    [WebGet(UriTemplate = "helloworld")]
    [OperationContract]
    public string HelloWorld()
    {
         return "Hello World!";
    }

}
于 2012-03-15T10:34:06.343 に答える