从外部网页

时间:2018-02-21 09:52:56

标签: c# web-services wcf soap invalidoperationexception

我正在尝试实现一个C#Soap WebService(我是服务器端),它将从我不拥有的网页调用!我有一些我必须满足的规范。

我创建了一个界面,你可以在这里看到:

[ServiceContract]
public interface IMyService
{
    [OperationContract]
    int connect();

    [OperationContract]
    int disconnect();

    [OperationContract]
    string login(string userName, string userPassword);
}

另一个接口调用ICrossdomain。规范说明必须在http://InserNameHere:8080/crossdomain.xml.

下达成
[ServiceContract]
public interface ICrossdomain
{
    [OperationContract, WebGet(UriTemplate = "/crossdomain.xml")]
    Stream GetCrossDomain();
}

在下文中,您可以看到实施的一部分:

public class MyService : IMyService, ICrossdomain
{
    public int connect()
    {
        log.LogInformation("Aufruf der Methode connect() Rückgabewert" + 0);
        DMSConnectResponseData crd = new DMSConnectResponseData(log);
        return crd.process();
    }
    public int disconnect()
    {
        log.LogInformation("Aufruf der Methode connect() Rückgabewert" + 0);
        DMSDisconnectResponseData drd = new DMSDisconnectResponseData(log);
        return drd.process();
    }

    public string login(string a_sDMSUserName, string a_sDMSUserPassword)
    {
        log.LogInformation("Aufruf der Methode login() mit den Parametern Username: "+a_sDMSUserName + " UserPassword " + a_sDMSUserPassword);
        DMSLoginReponseData lrd = new DMSLoginReponseData(log);

        String xml = lrd.process(a_sDMSUserName, a_sDMSUserPassword, SessionMap);
        return xml;
    }

我的服务的实施:

Uri baseAddress = new Uri("http://InsertURLhere:8080");
string address = "http://InsertURLhere:8080/ServiceName";
ecatHost = new ServiceHost(typeof(MyService), baseAddress);
ecatHost.AddServiceEndpoint(typeof(IMyService), new BasicHttpBinding(), address);
ecatHost.AddServiceEndpoint(typeof(ICrossdomain), new WebHttpBinding(), "").Behaviors.Add(new WebHttpBehavior());

ServiceMetadataBehavior smb = ecatHost.Description.Behaviors.Find<ServiceMetadataBehavior>();
if (smb == null)
{
    smb = new ServiceMetadataBehavior();
    smb.HttpGetEnabled = true;
    smb.MetadataExporter.PolicyVersion = PolicyVersion.Policy15;
    ecatHost.Description.Behaviors.Add(smb);
}

ecatHost.AddServiceEndpoint(ServiceMetadataBehavior.MexContractName, MetadataExchangeBindings.CreateMexHttpBinding(), "mex");

ecatHost.Open();

在我必须在wsdl中读取的网页上,指定url(InsertURLhere:8080 / ServiceName或不带/ ServiceName)和URN(在wsdl中读取之后它将被设置为BasicHttpBinding,不知道要在那里插入什么) 。之后我尝试连接到服务,在调试模式下它将跳转到MyService类的构造函数,然后我得到以下消息

  

“Ausnahmeausgelöst:”System.InvalidOperationException“in   System.ServiceModel.Web.dll“

任何人都知道如何获得更具体的异常消息或我必须在哪个方向上搜索以解决问题,因为老实说我对这个主题很新!

非常感谢提前!

0 个答案:

没有答案