Error calling a WCF service calling another WCF service

We have a requirement to call a WCF service from another WCF service. To test this, I am creating a sample console application to display a simple string. Settings: Console Application -> WCF Service 1 -> WCF Service 2 The console application calls the service 1 method, and the service 1 method ultimately calls the service 2 method to return a string. I can call the Console → Service 1, but Service 1 → Service 2 does not work. It throws an exception: “Could not find the default endpoint element that references the contract“ ITestService2 ”in the“ ServiceModel client configuration ”section. This may be because the configuration file was not found for your application or because the element the client could not find any endpoint element matching this contract. "To do this, I created the WCF 2 service using a single method that returns a string (nothing unusual).

namespace TestServices
{
    [ServiceContract]
    public interface ITestService2
    {
        [OperationContract]
        string GetSomething(string s);
    }
}

service1 - ITestService1.cs TestService1.cs, service2 GetSomething().

namespace TestServices
{
    [ServiceContract]
    public interface ITestService1
    {
        [OperationContract]
        string GetMessage(string s);
    }        
}

namespace TestServices
{
    class TestService1 : ITestService1
    {
        public string GetMessage(string s)
        {
            TestService2 client = new TestService2();
            return client.GetSomething("WELCOME " + s);
        }
    }
}

. Service2 svcutil.exe. app.config TestService2.cs, TestService1 .

, , Service1 GetMessage().

static void Main(string[] args)
{
    TestService1 client = new TestService1();
    Console.WriteLine(client.GetMessage("Roger Harper"));
    Console.ReadKey();
}

2 , - . - 1. . : config 1 :

<configuration>
    <system.serviceModel>
        <bindings>
            <wsHttpBinding>
                <binding name="WSHttpBinding_ITestService1" closeTimeout="00:01:00"
                    openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
                    bypassProxyOnLocal="false" transactionFlow="false" hostNameComparisonMode="StrongWildcard"
                    maxBufferPoolSize="524288" maxReceivedMessageSize="65536"
                    messageEncoding="Text" textEncoding="utf-8" useDefaultWebProxy="true"
                    allowCookies="false">
                    <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
                        maxBytesPerRead="4096" maxNameTableCharCount="16384" />
                    <reliableSession ordered="true" inactivityTimeout="00:10:00"
                        enabled="false" />
                    <security mode="Message">
                        <transport clientCredentialType="Windows" proxyCredentialType="None"
                            realm="" />
                        <message clientCredentialType="Windows" negotiateServiceCredential="true"
                            algorithmSuite="Default" establishSecurityContext="true" />
                    </security>
                </binding>
            </wsHttpBinding>
        </bindings>
        <client>
            <endpoint address="http://localhost:3227/WCFTestSite/TestService1.svc"
                binding="wsHttpBinding" bindingConfiguration="WSHttpBinding_ITestService1"
                contract="ITestService1" name="WSHttpBinding_ITestService1">
                <identity>
                    <dns value="localhost" />
                </identity>
            </endpoint>
        </client>
    </system.serviceModel>
</configuration>

2 service1:

<configuration>
    <system.serviceModel>
        <bindings>
            <wsHttpBinding>
                <binding name="WSHttpBinding_ITestService2" closeTimeout="00:01:00"
                    openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
                    bypassProxyOnLocal="false" transactionFlow="false" hostNameComparisonMode="StrongWildcard"
                    maxBufferPoolSize="524288" maxReceivedMessageSize="65536"
                    messageEncoding="Text" textEncoding="utf-8" useDefaultWebProxy="true"
                    allowCookies="false">
                    <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
                        maxBytesPerRead="4096" maxNameTableCharCount="16384" />
                    <reliableSession ordered="true" inactivityTimeout="00:10:00"
                        enabled="false" />
                    <security mode="Message">
                        <transport clientCredentialType="Windows" proxyCredentialType="None"
                            realm="" />
                        <message clientCredentialType="Windows" negotiateServiceCredential="true"
                            algorithmSuite="Default" establishSecurityContext="true" />
                    </security>
                </binding>
            </wsHttpBinding>
        </bindings>
        <client>
            <endpoint address="http://localhost:3227/WCFTestSite/TestService2.svc"
                binding="wsHttpBinding" bindingConfiguration="WSHttpBinding_ISriWCFTestService2"
                contract="ITestService2" name="WSHttpBinding_ITestService2">
                <identity>
                    <dns value="localhost" />
                </identity>
            </endpoint>
        </client>
    </system.serviceModel>
</configuration>

, - . , . , / , . !!! .

+3
1

, wcf, wcf. , wcf service1, dll, , . , , sice 1 dll, , . 2. , .

+1

Source: https://habr.com/ru/post/1767884/


All Articles