如果有人不调用 Web 服务,将数据发布到 URL 的最佳方式是什么?

发布于 2024-09-09 08:39:03 字数 1339 浏览 7 评论 0原文

好吧...我有一个大问题...好吧这里...通常如果我理解得很好...Web 服务的工作方式是我编写一个方法从数据库获取一些数据,然后再获取一些数据其他用户/客户端添加引用并调用我的服务并获取数据...现在就我而言,我必须获取数据并实际将其以 xml 形式发布到用户/客户端(也许是肥皂)我猜...所以这就是我所做的......

[Serializable]
public class MyClass
{  [SoapAttribute]
   public int id;
    [SoapIgnore]
        public int ToSkip;
} 

String XmlizedString = null; 
            MyClass obj= new MyClass ();
            MemoryStream memoryStream = new MemoryStream ( );
            XmlTypeMapping myMapping =
            (new SoapReflectionImporter().ImportTypeMapping
            (typeof(MyClass)));
            XmlSerializer xs = new XmlSerializer (myMapping);
            XmlTextWriter xmlTextWriter = new XmlTextWriter ( memoryStream, Encoding.UTF8 );

            xs.Serialize ( xmlTextWriter, obj );
            memoryStream = ( MemoryStream ) xmlTextWriter.BaseStream;
            XmlizedString = UTF8ByteArrayToString ( memoryStream.ToArray ( ) );
            using (System.Net.WebClient client = new System.Net.WebClient())      
           {
            // performs an HTTP POST
            status= client.UploadString("http:/somewebservice.com/" + webServiceName,                 XmlizedString); 
            }

所以基本上......我将其序列化为xml(和soap)并将其转换为字符串,然后将此字符串上传到Web服务url...... 我只是想知道我所做的是否正确?...我基本上想将数据转换为soap xml,然后将其发送到用户的网络服务网址...请帮助我...

Alright...I have kind of a big quesstion...ok here goes...Usually if i understand it well...web services work in a way that i write a method to get some data from the database and then some other user/client adds a reference and calls my service and gets the data...now in my case i have to get the data and actually post it to the user/client in xml(in soap maybe) i guess....so here is what i do...

[Serializable]
public class MyClass
{  [SoapAttribute]
   public int id;
    [SoapIgnore]
        public int ToSkip;
} 

String XmlizedString = null; 
            MyClass obj= new MyClass ();
            MemoryStream memoryStream = new MemoryStream ( );
            XmlTypeMapping myMapping =
            (new SoapReflectionImporter().ImportTypeMapping
            (typeof(MyClass)));
            XmlSerializer xs = new XmlSerializer (myMapping);
            XmlTextWriter xmlTextWriter = new XmlTextWriter ( memoryStream, Encoding.UTF8 );

            xs.Serialize ( xmlTextWriter, obj );
            memoryStream = ( MemoryStream ) xmlTextWriter.BaseStream;
            XmlizedString = UTF8ByteArrayToString ( memoryStream.ToArray ( ) );
            using (System.Net.WebClient client = new System.Net.WebClient())      
           {
            // performs an HTTP POST
            status= client.UploadString("http:/somewebservice.com/" + webServiceName,                 XmlizedString); 
            }

So basically....I serialize it to xml(and soap) and convert it to string and then upload this string to the web service url......
I just want to know if what i am doing is right?...i want to basically get the data convert it to soap xml and then send it over to the user's web service url....please help me out...

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

墨小墨 2024-09-16 08:39:03

这是基于 wsdl 的 Web 服务吗?如果是,那么只需使用 IDE 或某些工具来生成静态类型的客户端包装器。

在.NET环境中,可以使用Visual Studio或wsdl.exe

不要将原始数据发送到 url,也不要尝试手动解析响应,这太疯狂了。尤其是对于这些复杂的基于 SOAP 的 Web 服务。

Is this wsdl-based webservice? If yes, then just use your IDE or some tool to generate static-typed client wrapper.

In .NET environment, you can use visual studio or wsdl.exe

Don't send raw data to url and don't try to parse response manually, that's insane. Especially with these complex SOAP-based webservices.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文