0

Newbie implementing WS, and according to our infrastructures we have to use C#, so maybe will use WCF maybe,

The thing is that our system must store some info of payments that a third company will send us

  1. They send a request message (is a valid payment?)
  2. We Will validate the info and respond with message given an ok or not ok (will check in if the payment apply)
  3. If ok, they will send a message with the transaction done
  4. We will process the message and store the payment in our DB

But they just give us some xml messages examples and an excel files explaining the messages as xpath format (indicating the meanings, types and if it is mandatory). Once implemented we must notified them (no even a endpoint was given y, so I suppose we have to consider it as a variable). Seems that they have their ws implemented in java.

Reviewing tutorials and books, I think they should give us a WSDL file or is it possible to implement the services with just those xml samples? and if so what should be the process? How to build the proxy?

4

1 回答 1

0
  1. 解决此问题的更好方法之一是使用 SOA 的标准。您可以通过使用必要的服务契约创建一个简单的 WCF 服务来实现这一点。
  2. 为 XML 序列化创建一个帮助程序,它将帮助您创建请求并使用响应。使用System.Xml.Serialization.XmlSerializer类。
  3. 创建另一个帮助程序来创建一个 Http POST 帮助程序来访问您的第三方端点。下面的代码应该至少让你

    private static string PostData(string url, string postData, string contentType, string methodType)
    {
        var uri = new Uri(url);
    
        var request = (HttpWebRequest)WebRequest.Create(uri);
    
        request.Method = methodType;
    
        request.ContentType = contentType;
    
        request.ContentLength = postData.Length;
    
        using (Stream writeStream = request.GetRequestStream())
        {
            var encoding = new UTF8Encoding();
    
            byte[] bytes = encoding.GetBytes(postData);
    
            writeStream.Write(bytes, 0, bytes.Length);
        }
    
        string result;
    
        using (var response = (HttpWebResponse)request.GetResponse())
        {
            using (var responseStream = response.GetResponseStream() ?? new MemoryStream())
            {
                using (var readStream = new StreamReader(responseStream, Encoding.UTF8))
                {
                    result = readStream.ReadToEnd();
                }
            }
        }
    
        return result;
    }
    
于 2013-06-03T17:32:00.993 回答