wcf — soapURL для вызова службы Windows на C # через Soap в Stack Overflow

Проблема:

Я унаследовал программное обеспечение, в котором служба Windows C # вызывается с помощью PHP. Это не работает должным образом, поэтому я только начинаю на WCF и SOAP.

Моя главная проблема заключается в том, что я не могу вызвать службу Windows, используя PHP и Soap. Когда я пытаюсь это сделать, PHP падает.

Я закончил учебник Microsoft:
https://docs.microsoft.com/en-us/dotnet/framework/wcf/getting-started-tutorial
Когда я использую клиент C #, как описано в руководстве, все работает как charme. Я добавил установщик, чтобы сделать всю программу доступной в качестве службы Windows. Короче говоря, в C # все работает как положено.

Я предполагаю, что он просто не настроен правильно для вызова SOAP. Я уже прочитал: http://www.rizalalmashoor.com/blog/calling-a-wcf-service-from-php/ но я все еще не могу заставить его работать.

Вопросы:

Исходный код ниже. Я хотел поставить мои вопросы в первую очередь:

1) Я выставляю сервис по базовому адресу, верно ??

HTTP: // локальный: 1234 / GettingStartedLib / CalculatorService

2) Конечная точка http оставлена ​​пустой. Правильно ли мой soapURL в коде PHP?

3) Есть ли способ отладки мыльного звонка? Даже когда я отлаживаю его в ZendStudio как приложение CLI, я не получаю никакой дополнительной информации.

Я рад предоставить дополнительную информацию, если это необходимо или что-то не объясняется адекватно.

  • Прежде чем кто-то ответит: мыло включено в php.ini. Уже проверено на этом.

Исходный код:

PHP:

$soapURL = 'http://localhost:1234/GettingStartedLib/CalculatorService?wsdl';
$soapAttributes = array('soap_version' => SOAP_1_1);

$result = new SoapClient($soapURL, $soapAttributes);

Конфигурация библиотеки WCF:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
<appSettings>
<add key="aspnet:UseTaskFriendlySynchronizationContext" value="true"/>
</appSettings>
<system.web>
<compilation debug="true"/>
</system.web>
<!-- When deploying the service library project, the content of the config file must be added to the host's
app.config file. System.Configuration does not support config files for libraries. -->
<system.serviceModel>
<services>
<service name="GettingStartedLib.CalculatorService">
<host>
<baseAddresses>
<add baseAddress="http://localhost:1234/GettingStartedLib/CalculatorService"/>
</baseAddresses>
</host>
<!-- Service Endpoints -->
<!-- Unless fully qualified, address is relative to base address supplied above -->
<endpoint address="" binding="basicHttpBinding" contract="GettingStartedLib.ICalculator">
<!--
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>
<!-- Metadata Endpoints -->
<!-- The Metadata Exchange endpoint is used by the service to describe itself to clients. -->
<!-- This endpoint does not use a secure binding and should be secured or removed before deployment -->
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior>
<!-- To avoid disclosing metadata information,
set the values below to false before deployment -->
<serviceMetadata httpGetEnabled="True" httpsGetEnabled="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>
</behaviors>
</system.serviceModel>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.2"/>
</startup>
</configuration>

Интерфейс C #

namespace GettingStartedLib
{
[ServiceContract(Namespace = "http://Microsoft.ServiceModel.Samples")]
public interface ICalculator {
[OperationContract]
double Add(double n1, double n2);
[OperationContract]
double Subtract(double n1, double n2);
[OperationContract]
double Multiply(double n1, double n2);
[OperationContract]
double Divide(double n1, double n2);
[OperationContract]
string SoapCall();
}
}

Сам сервис C #:

namespace GettingStartedLib
{
public class CalculatorService : ICalculator
{
public double Add(double n1, double n2) {
double result = n1 + n2;
Console.WriteLine("Received Add({0},{1})", n1, n2);
// Code added to write output to the console window.
Console.WriteLine("Return: {0}", result);
return result;
}

public double Subtract(double n1, double n2) {
double result = n1 - n2;
Console.WriteLine("Received Subtract({0},{1})", n1, n2);
Console.WriteLine("Return: {0}", result);
return result;
}

public double Multiply(double n1, double n2) {
double result = n1 * n2;
Console.WriteLine("Received Multiply({0},{1})", n1, n2);
Console.WriteLine("Return: {0}", result);
return result;
}

public double Divide(double n1, double n2) {
double result = n1 / n2;
Console.WriteLine("Received Divide({0},{1})", n1, n2);
Console.WriteLine("Return: {0}", result);
return result;
}
public string SoapCall() => "SoapCall";
}
}

0

Решение

Решил проблему. Я должен был войти

<baseAddresses><add baseAddress="localhost:1234/GettingStartedLib/CalculatorService.vsc"/>
</baseAddresses>

Так как я оставил адрес конечной точки http пустым, мыльный URL был localhost:1234/GettingStartedLib/CalculatorService.vsc?wsdl

0

Другие решения

Других решений пока нет …

По вопросам рекламы [email protected]