1

私はこれを取得しています

HTTP エラー 404.0 - 見つかりません お探しのリソースは削除されているか、名前が変更されているか、一時的に利用できません。

ブラウザからサービスにアクセスしようとしたとき。ここに私の設定があります。

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
    <system.serviceModel>

        <services>
            <!-- Note: the service name must match the configuration name for the service implementation. -->
            <service name="WcfServiceLibrary.Service1" behaviorConfiguration="MyServiceTypeBehaviors" >
                <!-- Add the following endpoint.  -->
                <!-- Note: your service must have an http base address to add this endpoint. -->
                <endpoint contract="WcfServiceLibrary.Service1" binding="basicHttpBinding" address="http://localhost/service1" />
                <endpoint contract="IMetadataExchange" binding="mexHttpBinding" address="http://localhost/service1/mex" />
            </service>
        </services>

        <behaviors>
            <serviceBehaviors>
                <behavior name="MyServiceTypeBehaviors" >
                    <!-- Add the following element to your service behavior configuration. -->
                    <serviceMetadata httpGetEnabled="true" httpGetUrl="http://localhost/service1" />
                </behavior>
            </serviceBehaviors>
        </behaviors>

    </system.serviceModel>

</configuration>

Web ブラウザーにhttp://localhost/service1と入力すると、404 が返されます。

string serviceUrl = "http://localhost/service1";
 Uri uri = new Uri(serviceUrl);
 host = new ServiceHost(typeof(Service1), uri);
host.Open();

すべてうまくいきます...何かアイデアはありますか?十分に単純に思えます。

4

2 に答える 2

3

サービスの下にホスト要素がないと思います:

<service name="WcfServiceLibrary2.Service1">
    <host>
        <baseAddresses>
            <add baseAddress = "http://localhost/service1" />
        </baseAddresses>
    </host>
    <endpoint address ="" binding="wsHttpBinding" contract="WcfServiceLibrary2.IService1">
        <identity>
            <dns value="localhost"/>
        </identity>
    </endpoint>
    <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
</service>

その場合、サービス ホストには URL は必要ありません。

    static void Main(string[] args)
    {
        var host = new ServiceHost(typeof(Service1));
        host.Open();

        Console.WriteLine("Host running");
        Console.ReadLine();
    }
于 2012-04-15T20:46:27.317 に答える
0

ブラウザーでhttp://localhost/service1? Wsdl を表示できますが、mex はサービス参照の追加または WCFTestClient (C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE) でのみ機能します。これは、HTTP を取得するためです。メッセージの内容が HTTP ヘッダーにあり、本文が空である HTTP GET 要求をブラウザが発行するという事実に起因する Bad Request エラー。

これはまさに、WCF の mexHttpBinding が不平を言っていることです。

于 2012-04-16T14:53:57.273 に答える