简体   繁体   English

C# Web 应用与 SOAP 响应

[英]C# Web Application with SOAP Response

I'm fairly new to programming an C# and i need to create a web application project.我对 C# 编程相当陌生,我需要创建一个 web 应用程序项目。 I have been told that a website will navigate to my web application and send an ID.有人告诉我,一个网站将导航到我的 web 应用程序并发送一个 ID。 My web application then needs to use this ID within a SOAP request.然后,我的 web 应用程序需要在 SOAP 请求中使用此 ID。 The responce then needs to be evaluated and if it fits a criteria, the web application can load or else just throws an exception.然后需要评估响应,如果它符合标准,则 web 应用程序可以加载,否则只会引发异常。

I can code all the application except grabbing the initial ID and setting up a SOAP request and recieve.除了获取初始 ID 并设置 SOAP 请求并接收之外,我可以编写所有应用程序。 I have all the relevant information, i just don't know how to set up the SOAP request/responce.我有所有相关信息,我只是不知道如何设置 SOAP 请求/响应。

Best Regards此致

Assuming you are using a WCF, it uses SOAP by default, so if you have everything setup correctly, it will automatically serialize and deserialize for you.假设您使用的是 WCF,它默认使用 SOAP,因此如果您正确设置了所有内容,它将自动为您进行序列化和反序列化。

[OperationContract]
MyResponse ParseId(MyRequest req);

MyResponse can hold response information MyRequest can hold request information MyResponse 可以保存响应信息 MyRequest 可以保存请求信息

Implementation could be like this:实现可能是这样的:

public MyResponse ParseId(MyRequest req)
{
    if(req.Id == null)
    {
       //Error
    }
    else
    {

    }
 }

If it is really simple, you can do something like this:如果它真的很简单,你可以这样做:

[OperationContract]
void ParseId(int id);

Implementation:执行:

public void ParseId(int id)
{
  if(id == null)
  {
      //throw exception;
  }
  else
  {

  }
}

Don't forget to decorate your MyResponse class and MyRequest class with DataContract attributes.不要忘记使用 DataContract 属性装饰您的 MyResponse class 和 MyRequest class 。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM