开发者

Error in using WCF service

开发者 https://www.devze.com 2023-03-07 02:48 出处:网络
I am facing below error when i try to use my service. There was no endpoint listening at http://myip:84/service1.svc/ that could accept the message. This is often caused by an incorrect address or SO

I am facing below error when i try to use my service.

There was no endpoint listening at http://myip:84/service1.svc/ that could accept the message. This is often caused by an incorrect address or SOAP action.

My Service Code:

<system.serviceModel>

        <services>
            <service name="wcftest1.Service1" behaviorConfiguration="wcftest1.Service1Behavior">


                <endpoint address="http://myip:84/Service1.svc/" behaviorConfiguration="epbeh" bindingConfiguration ="webConfig" binding="webHttpBinding" contract="wcftest1.IService1">
                </endpoint>

                <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>

            </service>

        </services>

        <bindings>
            <basicHttpBinding>
                <binding name="basicConfig" >
                </binding>
            </basicHttpBinding>
            <webHttpBinding>
                <binding name="webConfig">

                </binding>

            </webHttpBinding>

        </bindings>
        <behaviors>
            <serviceBehaviors>
                <behavior name="wcftest1.Service1Behavior" >
                    <!-- 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"/>
                    <serviceCredentials>
                        <userNameAuthentication userNamePasswordValidationMode="Custom"  customUserNamePasswordValidatorType="wcftest1.validateUser, wcftest1"/>
                    </serviceCredentials>

                </behavior>
            </serviceBehaviors>
            <endpointBehaviors>
                <behavior name="epbeh">
                    <webHttp />
                </behavior>
            </endpointBehaviors>
        </behaviors>

Service Class:

[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
    public class Service1 : IService1
    {

Service Interface:

[OperationContract]
        [WebGet(ResponseFormat= WebMessageFormat.Json)]
        string GetMsg();

Client webconfig:

    <system.serviceModel>
        <bindings>
   <customBinding>
    <binding name="WebHttpBinding_IService1">
     <textMessageEncoding maxReadPoolSize="64" maxWritePoolSize="16"
      messageVersion="Soap12" writeEncoding="utf-8">
      <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
       maxBytesPerRead="4096" maxNameTableCharCount="16384" />
     </textMessageEncoding>
        <httpTransport/>
   开发者_如何学运维 </binding>

   </customBinding>
  </bindings>
        <client>
   <endpoint binding="customBinding" address="http://myip:84/service1.svc/" bindingConfiguration="WebHttpBinding_IService1"
    contract="ServiceReference1.IService1" name="WebHttpBinding_IService1" />
  </client>
    </system.serviceModel>

Client COde:

 ServiceReference1.Service1Client sc = new userwcftest1.ServiceReference1.Service1Client();

            Response.Write(sc.GetData(5));

my service will be used by PHP developers and its built on .NET framework 3.5, and i am to return JSON. I am new to WCF.

Please help me Thanks


The client uses a different binding than the service - client uses a custom binding with message version SOAP 1.2; the server uses webHttpBinding, which is roughly equivalent to a custom binding with MessageVersion.None (it's REST, not SOAP).

You added a mex endpoint on the service, but REST endpoints do not emit metadata, so whatever you generated with svcutil / add service reference won't work.

One way to call your service is to simply use something like below:

WebClient c = new WebClient();
string result = c.DownloadString("http://myip:84/service1.svc/GetMsg");
0

精彩评论

暂无评论...
验证码 换一张
取 消