вот мой код сервера WCF (VB.NET) ...
Service1.svc
Public Class Service1
Implements IService1
Public Sub New()
End Sub
Public Function GetText() As String Implements IService1.GetText
Return String.Format("YO MTV ROCKS!")
End Function
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
IService1.vb
' NOTE: You can use the "Rename" command on the context menu to change the interface
name "IService1" in both code and config file together.
<ServiceContract()>
Public Interface IService1
<OperationContract()> _
<WebGet(UriTemplate:="GetText", BodyStyle:=WebMessageBodyStyle.WrappedRequest, responseformat:=WebMessageFormat.Json, RequestFormat:=WebMessageFormat.Json)> _
Function GetText() As String
<OperationContract()> _
<WebGet(UriTemplate:="GetData?v={value}", responseformat:=WebMessageFormat.Json)> _
Function GetData(ByVal value As Integer) As String
<OperationContract()>
Function GetDataUsingDataContract(ByVal composite As CompositeType) As CompositeType
' TODO: Add your service operations here
End Interface
' Use a data contract as illustrated in the sample below to add composite types to service operations.
<DataContract()>
Public Class CompositeType
<DataMember()>
Public Property BoolValue() As Boolean
<DataMember()>
Public Property StringValue() As String
Конечный класс
Web.config
<?xml version="1.0"?>
<configuration>
<system.web>
<compilation debug="true" strict="false" explicit="true" targetFramework="4.0" />
<customErrors mode="Off"/>
</system.web>
<system.serviceModel>
<behaviors>
<endpointBehaviors>
<behavior name="httpBehavior">
<webHttp />
</behavior>
</endpointBehaviors>
<serviceBehaviors>
<behavior name="">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="false" />
</behavior>
</serviceBehaviors>
</behaviors>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
<services>
<service name="HttpWcfWeb.VehicleService">
<endpoint address=""
behaviorConfiguration="httpBehavior"
binding="webHttpBinding"
contract="HttpWcfWeb.IVehicleService" />
</service>
</services>
</system.serviceModel>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true"/>
</system.webServer>
</configuration>
вот мой код Android-клиента ...
public static final String _URL = "http://192.168.212.37:8080/Service1.svc";
protected void logIn(){
try
{
// Send GET request to <service>/GetText
HttpGet request = new HttpGet(_URL + "/GetText");
request.setHeader("Accept", "application/json");
request.setHeader("Content-type", "application/json");
DefaultHttpClient httpClient = new DefaultHttpClient();
HttpResponse response = httpClient.execute(request);
HttpEntity responseEntity = response.getEntity();
// Read response data into buffer
long intCount = responseEntity.getContentLength();
char[] buffer = new char[(int)responseEntity.getContentLength()];
InputStream stream = responseEntity.getContent();
InputStreamReader reader = new InputStreamReader(stream);
reader.read(buffer);
stream.close();
tvStatus.append("response: ");
JSONArray plates = new JSONArray(new String(buffer));
for (int i = 0; i < plates.length(); ++i) {
tvStatus.append(plates.getString(i));
}
} catch (Exception e) {
e.printStackTrace();
}
}
По какой-то неизвестной причине я могу запустить клиентский тест VS 2010, и хост WCF работает нормально. Код выше просто ничего не возвращает (он должен возвращать строку)
есть идеи, что я делаю не так?