gpt4 book ai didi

java - android java消费vb.net wcf服务

转载 作者:行者123 更新时间:2023-12-02 06:17:40 24 4
gpt4 key购买 nike

如何让 android java 使用 vb.net wcf 服务,

这就是 VB.net 控制台应用程序连接到 wcf 服务的样子。我该如何用JAVA写这个?

    ''http://localhost:9999/Service1.svc
Dim client As ServiceReference1.Service1Client = New ServiceReference1.Service1Client()
Dim s As String = client.GetData(2)
client.Close()
<小时/>
package com.example.test;

import android.os.Bundle;
import android.app.Activity;
import android.app.AlertDialog;
import android.view.Menu;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;

public class MainActivity extends Activity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

}



@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}


private void getServiceNow(){

//this is how it looks in a VB.net Console app to connect to a wcf service
//http://localhost:9999/Service1.svc
//Dim client As ServiceReference1.Service1Client = New ServiceReference1.Service1Client()
//Dim s As String = client.GetDatas(2)
//client.Close()
}



}
<小时/>

wcf服务的web.config

<?xml version="1.0"?>
<configuration>

<system.web>
<compilation debug="true" strict="false" explicit="true" targetFramework="4.0" />
</system.web>
<system.serviceModel>
<behaviors>
<serviceBehaviors>
<behavior>
<!-- To avoid disclosing metadata information, set the value below to false before deployment -->
<serviceMetadata httpGetEnabled="true"/>
<!-- To receive exception details in faults for debugging purposes, set the value below to true. Set to false before deployment to avoid disclosing exception information -->
<serviceDebug includeExceptionDetailInFaults="false"/>
</behavior>
</serviceBehaviors>
</behaviors>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
</system.serviceModel>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true"/>
<!--
To browse web app root directory during debugging, set the value below to true.
Set to false before deployment to avoid disclosing web app folder information.
-->
<directoryBrowse enabled="true"/>
</system.webServer>

</configuration>
<小时/>
Public Class Service1
Implements IService1

Public Sub New()
End Sub

Public Function GetData(ByVal value As Integer) As String Implements IService1.GetData


Return String.Format("You entered: {0}", value)
End Function

Public Function GetDataUsingDataContract(ByVal composite As CompositeType) As CompositeType Implements IService1.GetDataUsingDataContract
If composite Is Nothing Then
Throw New ArgumentNullException("composite")
End If
If composite.BoolValue Then
composite.StringValue &= "Suffix"
End If
Return composite
End Function


End Class
<小时/>

最佳答案

这不是工作代码,但它为您提供了如何从 Android 调用服务的基本概念。

HttpPost request = new HttpPost("http://localhost:9999/Service1.svc/GetDatas");
request.setHeader("Accept", "application/xml");
request.setHeader("Content-type", "application/xml");
StringEntity entity = new StringEntity(2);
request.setEntity(entity);
DefaultHttpClient httpClient = new DefaultHttpClient();
HttpResponse response = httpClient.execute(request);

String ss1=EntityUtils.toString(response.getEntity());

关于java - android java消费vb.net wcf服务,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21305517/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com