本文介绍了Web服务无法正常工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用vb.net 1.1版在本地计算机上创建了一个Web服务(C:\ Inetpub \ www.root \ Confverter)。


webservice的用途:此Web服务将由第三方网站(例如abc.com)调用。用户将在abc.com的网页中添加一条消息,此消息将发送到Web服务。


下面提到的是我为Web服务编写的用于存储参数的代码/第三方应用程序发送的消息。


- Service1.asmx page

[code]

Imports System.Web.Services

Imports System.Web

Imports System.Data.SqlClient

Imports System.Collections.Specialized

Imports System。 Web.Services.Protocols


< System.Web.Services.WebService(Namespace:=" http://www.MyWebsiteAddress.com/Converter/Service1 ")> _
$
公共舱服务1

   继承System.Web.Services.WebService


    'WEB服务示例

    'HelloWorld()示例服务返回字符串Hello World。

    '要构建,取消注释以下行,然后保存并构建项目。

    '要测试此网络服务,请确保.asmx文件是起始页面。
    '并按F5。




    <的WebMethod()> _
$
    Public Sub ProcessRequest(ByVal userKey As String,ByVal message As String,ByVal listen As String)//这里提到的参数将被发送到此Web服务

      ; Dim strcon As String

        strcon =" server = ip;数据库= dbname;开发UID = XXX; pwd = XXX"

        Dim objConn As New SqlConnection(strcon)

        Dim objTrans As SqlTransaction

        objConn.Open()

        objTrans = objConn.BeginTransaction

        Dim strSQL As String =""

        strSQL =" insert into TableName(UserKey,Message,Voicelink)值"

        strSQL = strSQL +"('"& userKey&"','"& message&"','"& listen&"')"
        Dim cmd As New SqlCommand(strSQL,objConn)

        cmd.Transaction = objTrans

        cmd.CommandType = Data.CommandType.Text

        cmd.ExecuteNonQuery()

        objTrans.Commit()


   结束子


结束等级

[/ code]

在本地envoirement上测试网络服务后,我发现它正在工作正常。 I&NBSP;将service1.asmx,service1.asmx.vb文件上传到在线开发Web服务器源代码的根目录,并将Converter.dll和Converter.pdb
文件上传到Web服务器的bin文件夹。

执行此过程后,我通过[url] http://MyWebsiteName.com/Service1.asmx [/ url]测试了网络服务,并收到错误[I]"测试表单仅适用于来自本地计算机的请求" [/ I]。为了解决这个错误我 在Web服务的web.config中的web.cong文件中添加了下面提到的代码


[code]

< webServices>

  < protocols>

   < add name =" HttpGet" />

  < add name =" HttpPost" />

 < / protocols>

 < / webServices>在添加上述代码后,
[/ code]

通过浏览器正常运行webservice。


现在第三方应用程序已经要求输入webservice的链接,该链接将在用户添加消息时收到命中,因此我将其作为[url] http://MyWebsiteName.com/Service1.asmx [/ url]。


但是当我尝试从第三方应用程序发送消息作为真实envoirenment中的测试的一部分时,我应该对上面提到的URL(Web服务)有所了解,但是,我没有受到打击(数据没有保存到数据库中。


所以,我认为,我的Web服务没有正确部署(我已经完成了处理文件和.DLL到开发服务器的工作)不足以从第三方获得命中)或者在SUB ProcessRequest中编写的代码无法从第三方应用程序接收
查询字符串参数。


请注意我正在Microsoft Visual Studio .NET 20中创建Web服务03使用VB.net


请帮助它紧急。


谢谢,


Govind

解决方案

I have created a web service on my local machine (C:\Inetpub\wwwroot\Converter) using vb.net version 1.1.

Purpose of webservice: this webservice will be invoked by a third party website (say abc.com). User will add a message in a webpage of abc.com this message will be sent to the Webservice.

Below mentioned is the code that I have written for a web service to store the parameters/message sent by third party application.

-- Service1.asmx page
[code]
Imports System.Web.Services
Imports System.Web
Imports System.Data.SqlClient
Imports System.Collections.Specialized
Imports System.Web.Services.Protocols

<System.Web.Services.WebService(Namespace:="http://www.MyWebsiteAddress.com/Converter/Service1")> _
Public Class Service1
    Inherits System.Web.Services.WebService

    ' WEB SERVICE EXAMPLE
    ' The HelloWorld() example service returns the string Hello World.
    ' To build, uncomment the following lines then save and build the project.
    ' To test this web service, ensure that the .asmx file is the start page
    ' and press F5.


    <WebMethod()> _
    Public Sub ProcessRequest(ByVal userKey As String, ByVal message As String, ByVal listen As String) // Mentioned here are the parameters will be sent to this web service
      Dim strcon As String
        strcon = "server=ip; database=dbname; uid=XXX; pwd=XXX"
        Dim objConn As New SqlConnection(strcon)
        Dim objTrans As SqlTransaction
        objConn.Open()
        objTrans = objConn.BeginTransaction
        Dim strSQL As String = ""
        strSQL = "insert into TableName (UserKey,Message,Voicelink)values"
        strSQL = strSQL + "('" & userKey & "','" & message & "','" & listen & "')"
        Dim cmd As New SqlCommand(strSQL, objConn)
        cmd.Transaction = objTrans
        cmd.CommandType = Data.CommandType.Text
        cmd.ExecuteNonQuery()
        objTrans.Commit()

    End Sub

End Class
[/code]
After testing the web service on a local envoirement I found that it is working properly. I  uploaded service1.asmx, service1.asmx.vb files to the root directory of source code of online development web server and uploaded Converter.dll and Converter.pdb file to the bin folder of web server.
After doing this process i tested the webservice by [url]http://MyWebsiteName.com/Service1.asmx[/url] and recived error [I]"The test form is only available for requests from the local machine.".[/I]. To resolve this error I  added below mentioned code in the web.cong file of application not in the web.config of Webservice.
[code]
<webServices>
  <protocols>
   <add name="HttpGet"/>
  <add name="HttpPost"/>
 </protocols>
 </webServices>
[/code]
after adding the above code webservice was working properly through the browser.

Now the third party application has asked to enter the link of webservice which will receive the hit when user add the message, so I have given it as [url]http://MyWebsiteName.com/Service1.asmx[/url].

But when I try to send the message from third party application as a part of testing in a real envoirenment I should get a hit to the above mentioned URL (Web Service), But, I'm not getting a hit(Data is not saved into the database).

So, I think, either my web service is not deployed properly (the porcess I have done of coping the files and .DLL to the development server is not sufficent to get the hit from third party) or the code written in SUB ProcessRequest is not able to recieve the query string parameters from the thrid party application.

Please note that I'm creating the web service in Microsoft Visual Studio .NET 2003 using VB.net

Please help its urgent.

Thanks,

Govind

解决方案


这篇关于Web服务无法正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-24 00:19