.NET에서 ComVisible 라이브러리를 개발 중이며 이전 VB6 클래스에서 호출됩니다. 기본적으로 클래스에서 수행하는 작업은 응답을 파싱하고 필요한 데이터가있는 객체를 반환하는 웹 서비스를 호출하는 것입니다. 잘못된 매개 변수로 호출 된 경우 SoapException
을 반환하도록 웹 서비스가 설계되었습니다. SoapException이 ComVisible 클래스에서 catch되지 않았습니다.
private static WCFPersonClient _client;
private static ReplyObject _reply;
public BFRWebServiceconnector()
{
_client = new WCFPersonClient("WSHttpBinding_IWCFPerson");
_reply = new ReplyObject();
}
[ComVisible(true)]
public ReplyObject GetFromBFR(string bestallningsID, string personnr, bool reservNummer = false)
{
try
{
var response = new XmlDocument();
//the service operation returns XML but the method in the generated service reference returns a string for some reason
var responseStr = _client.GetUserData(orderID, personnr, 3); reason.
response.LoadXml(responseStr);
//parse the response and fill the reply object
.......
}
catch (Exception ex)
{
_reply.Error = "Error: " + ex.Message;
if (_client.InnerChannel.State == CommunicationState.Faulted) _client = new WCFPersonClient("WSHttpBinding_IWCFPerson"); //recreate the failed channel
}
return _reply;
}
내가 올바른 매개 변수 내 VB6 코드에서이 메소드를 호출하려고하면
, 나는 적절한 대답을 얻을 : 여기 내 코드의 일부이다. 하지만 잘못된 매개 변수를 호출하면 VB32 프로그램에서-245757
(
Object reference was not set to an instance of an object
) 런타임 오류가 발생하고 이 채워진
Error
필드가있는 반면 내 C# 코드에서는
catch
절에 의해 캐치되지 않는 것으로 보입니다 메서드에서 반환 됨).
테스트 C# 프로젝트를 만들고 동일한 방법 (예 : .NET 플랫폼 내에서 동일한 웹 서비스를 호출 함)을 복사했으며이 경우 SoapException
이 제대로 캐치되고 있음을 확인할 수 있습니다.
이 동작은 의도적입니까? ComVisible 클래스 내에서 SoapException
을 잡을 수있는 방법이 있습니까 (실제로 내 답장 객체에 오류 메시지를 포함시키고 싶습니다)?
UPD : 내 VB6 코드는 다음입니다 :
Set BFRWSCReply = New ReplyObject
Set BFRWSC = New BFRWebbServiceconnector
Set BFRWSCReply = BFRWSC.GetFromBFR(m_BeställningsID, personnr)
If Not IsNull(BFRWSCReply) Then
If BFRWSCReply.Error= "" Then
m_sEfternamn = BFRWSCReply.Efternamn
//etc i.e. copy fields from the ReplyObject
Else
MsgBox BFRWSCReply.Error, vbExclamation
End If
End If
catch 절에 오류가 설정되어있는 동안 _replay 개체가 초기화되지 않았을 수 있습니다. _reply.Error = "Error :"Error : "+ ex.Message;' – Algirdas
@algirdas, 아니요, 생성자에서 초기화됩니다. – Azimuth
VB의 런타임 오류는 무엇입니까? –