Tôi phải gọi dịch vụ WCF an toàn từ java bằng cách sử dụng xác thực lẫn nhau. Mọi thứ hoạt động tốt trừ khi tôi không thể gửi tin nhắn có kích thước lớn hơn 48680 byte. Vì vậy, 48680 byte tin nhắn được gửi thành công, nhưng 48681 byte - không, và ứng dụng java không thành công với ngoại lệ đọc hết thời gian, mặc dù thiết lập hạn ngạch của WCF cho phép các thông điệp lớn hơn nhiều.Không thể gửi thư 48681 byte để bảo mật dịch vụ wcf từ java
Vì vậy, vấn đề có thể là gì?
EDIT
Mã nguồn:
package foo.bar;
import org.apache.commons.io.FileUtils;
import org.apache.commons.io.IOUtils;
import org.junit.Test;
import javax.net.ssl.*;
import java.io.*;
import java.net.URL;
import java.security.KeyStore;
public class ReadTimedOutTest {
@Test
public void testReadTimedOut() throws Exception {
URL url = new URL("https://services/endpoint/");
HttpsURLConnection connection = (HttpsURLConnection) url.openConnection();
setUpSSL(connection);
connection.setDoOutput(true);
connection.setDoInput(true);
connection.setRequestMethod("POST");
connection.setRequestProperty("SOAPAction", "http://namespace/2012/01/service/Operation");
connection.setRequestProperty("Accept", "*/*");
connection.setRequestProperty("Connection", "Keep-Alive");
connection.setRequestProperty("Content-Type", "text/xml; charset=utf-8");
connection.setConnectTimeout(10 * 1000);
connection.setReadTimeout(10 * 1000);
connection.setInstanceFollowRedirects(true);
ByteArrayOutputStream bos = new ByteArrayOutputStream();
InputStream is = ReadTimedOutTest.class.getResourceAsStream("payload.failure.xml");
try {
IOUtils.copy(is, bos);
} finally {
is.close();
}
byte[] bytes = bos.toByteArray();
connection.setRequestProperty("Content-Length", String.valueOf(bytes.length));
OutputStream os = connection.getOutputStream();
try {
IOUtils.copy(new ByteArrayInputStream(bytes), os);
os.flush();
} finally {
os.close();
}
int respCode = connection.getResponseCode();
if(respCode >= HttpsURLConnection.HTTP_INTERNAL_ERROR) {
is = connection.getErrorStream();
try {
IOUtils.copy(is, System.err);
} finally {
is.close();
}
} else {
is = connection.getInputStream();
try {
IOUtils.copy(is, System.out);
} finally {
is.close();
}
}
}
private void setUpSSL(HttpsURLConnection connection) throws Exception {
byte[] bytes = FileUtils.readFileToByteArray(new File("d:\\workspace\\temp\\keystore"));
KeyStore keyStore = KeyStore.getInstance("JKS");
keyStore.load(new ByteArrayInputStream(bytes), "changeit".toCharArray());
KeyManagerFactory keyManagerFactory = KeyManagerFactory.getInstance("X509");
keyManagerFactory.init(keyStore, "changeit".toCharArray());
bytes = FileUtils.readFileToByteArray(new File("d:\\workspace\\temp\\truststore"));
KeyStore trustStore = KeyStore.getInstance("JKS");
trustStore.load(new ByteArrayInputStream(bytes), "changeit".toCharArray());
TrustManagerFactory trustManagerFactory = TrustManagerFactory.getInstance("X509");
trustManagerFactory.init(trustStore);
SSLContext context = SSLContext.getInstance("TLS");
context.init(keyManagerFactory.getKeyManagers(), trustManagerFactory.getTrustManagers(), null);
SSLSocketFactory socketFactory = context.getSocketFactory();
connection.setSSLSocketFactory(socketFactory);
}
}
CẬP NHẬT
Tôi đã thử nghiệm dịch vụ với khách hàng WCF .net và nó đã có thể gọi serv băng thành công, vì vậy tôi tự hỏi điều gì có thể là vấn đề? Tại sao WCF khách hàng có thể gọi dịch vụ và máy khách Java, ngay cả khi sử dụng yêu cầu HTTP POST thông thường với UrlConnection, phải không?
CẬP NHẬT
Dưới đây là mẫu thông điệp xà phòng
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<DoSomethingUseful xmlns="http://namespace/2012/01/service">
...
</DoSomethingUseful>
</soap:Body>
</soap:Envelope>
CẬP NHẬT
tôi được cho biết rằng ở phía bên dịch vụ .net có "Client certificate is required. No certificate was found in the request" các thông báo dường như xảy ra khi nối lại phiên ssl. Nó chỉ xảy ra khi Content-Length lớn hơn 48680 bytes. Dịch vụ WCF cũng được cấu hình với basicHttpBinding để sử dụng bảo mật mức truyền tải.
Bạn có thể cung cấp cấu hình dịch vụ WCF của mình không? –
Thật không may đây là dịch vụ bên ngoài được sử dụng bởi tổ chức mà tôi đang làm việc. Có lẽ tôi sẽ có được cấu hình vào thứ hai. Sự cố chỉ xảy ra khi tôi đang cố gửi yêu cầu đủ lớn. Khi nhận được phản hồi lớn, không có vấn đề gì. Nhà phát triển dịch vụ WCF nói rằng không có bất kỳ vấn đề nào khi gọi dịch vụ này bằng ứng dụng khách .net từ mạng nội bộ của họ. – szhem
Có phải họ đang sử dụng cùng điểm cuối với bạn từ mạng nội bộ của họ không? –